summaryrefslogtreecommitdiffstats
path: root/src/lib-dict/dict-transaction-memory.h
blob: 2164c1e30381a765a84166ae09eb76b45d1db442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef DICT_TRANSACTION_MEMORY_H
#define DICT_TRANSACTION_MEMORY_H

#include "dict-private.h"

enum dict_change_type {
	DICT_CHANGE_TYPE_SET,
	DICT_CHANGE_TYPE_UNSET,
	DICT_CHANGE_TYPE_INC
};

struct dict_transaction_memory_change {
	enum dict_change_type type;
	const char *key;
	union {
		const char *str;
		long long diff;
	} value;
};

struct dict_transaction_memory_context {
	struct dict_transaction_context ctx;
	pool_t pool;
	ARRAY(struct dict_transaction_memory_change) changes;
};

void dict_transaction_memory_init(struct dict_transaction_memory_context *ctx,
				  struct dict *dict, pool_t pool);
void dict_transaction_memory_rollback(struct dict_transaction_context *ctx);

void dict_transaction_memory_set(struct dict_transaction_context *ctx,
				 const char *key, const char *value);
void dict_transaction_memory_unset(struct dict_transaction_context *ctx,
				   const char *key);
void dict_transaction_memory_atomic_inc(struct dict_transaction_context *ctx,
					const char *key, long long diff);

#endif