8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen#ifndef DICT_TRANSACTION_MEMORY_H
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen#define DICT_TRANSACTION_MEMORY_H
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen#include "dict-private.h"
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenenum dict_change_type {
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen DICT_CHANGE_TYPE_SET,
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen DICT_CHANGE_TYPE_UNSET,
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen DICT_CHANGE_TYPE_INC
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen};
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenstruct dict_transaction_memory_change {
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen enum dict_change_type type;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen const char *key;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen union {
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen const char *str;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen long long diff;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen } value;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen};
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenstruct dict_transaction_memory_context {
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen struct dict_transaction_context ctx;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen pool_t pool;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct dict_transaction_memory_change) changes;
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen};
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenvoid dict_transaction_memory_init(struct dict_transaction_memory_context *ctx,
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen struct dict *dict, pool_t pool);
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenvoid dict_transaction_memory_rollback(struct dict_transaction_context *ctx);
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenvoid dict_transaction_memory_set(struct dict_transaction_context *ctx,
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen const char *key, const char *value);
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenvoid dict_transaction_memory_unset(struct dict_transaction_context *ctx,
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen const char *key);
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainenvoid dict_transaction_memory_atomic_inc(struct dict_transaction_context *ctx,
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen const char *key, long long diff);
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen#endif