]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/include/libpmemobj/tx.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2014-2020, Intel Corporation */
5 * libpmemobj/tx.h -- definitions of libpmemobj transactional macros
8 #ifndef LIBPMEMOBJ_TX_H
9 #define LIBPMEMOBJ_TX_H 1
14 #include <libpmemobj/tx_base.h>
15 #include <libpmemobj/types.h>
21 #ifdef POBJ_TX_CRASH_ON_NO_ONABORT
22 #define TX_ONABORT_CHECK do {\
23 if (_stage == TX_STAGE_ONABORT)\
27 #define TX_ONABORT_CHECK do {} while (0)
30 #define _POBJ_TX_BEGIN(pop, ...)\
33 enum pobj_tx_stage _stage;\
35 if (setjmp(_tx_env)) {\
36 errno = pmemobj_tx_errno();\
38 _pobj_errno = pmemobj_tx_begin(pop, _tx_env, __VA_ARGS__,\
43 while ((_stage = pmemobj_tx_stage()) != TX_STAGE_NONE) {\
47 #define TX_BEGIN_PARAM(pop, ...)\
48 _POBJ_TX_BEGIN(pop, ##__VA_ARGS__)
50 #define TX_BEGIN_LOCK TX_BEGIN_PARAM
52 /* Just to let compiler warn when incompatible function pointer is used */
53 static inline pmemobj_tx_callback
54 _pobj_validate_cb_sig(pmemobj_tx_callback cb
)
59 #define TX_BEGIN_CB(pop, cb, arg, ...) _POBJ_TX_BEGIN(pop, TX_PARAM_CB,\
60 _pobj_validate_cb_sig(cb), arg, ##__VA_ARGS__)
62 #define TX_BEGIN(pop) _POBJ_TX_BEGIN(pop, TX_PARAM_NONE)
65 pmemobj_tx_process();\
67 case TX_STAGE_ONABORT:
70 pmemobj_tx_process();\
72 case TX_STAGE_ONCOMMIT:
75 pmemobj_tx_process();\
77 case TX_STAGE_FINALLY:
80 pmemobj_tx_process();\
84 pmemobj_tx_process();\
88 _pobj_errno = pmemobj_tx_end();\
94 pmemobj_tx_add_range((o).oid, 0, sizeof(*(o)._type))
96 #define TX_ADD_FIELD(o, field)\
97 TX_ADD_DIRECT(&(D_RO(o)->field))
99 #define TX_ADD_DIRECT(p)\
100 pmemobj_tx_add_range_direct(p, sizeof(*(p)))
102 #define TX_ADD_FIELD_DIRECT(p, field)\
103 pmemobj_tx_add_range_direct(&(p)->field, sizeof((p)->field))
105 #define TX_XADD(o, flags)\
106 pmemobj_tx_xadd_range((o).oid, 0, sizeof(*(o)._type), flags)
108 #define TX_XADD_FIELD(o, field, flags)\
109 TX_XADD_DIRECT(&(D_RO(o)->field), flags)
111 #define TX_XADD_DIRECT(p, flags)\
112 pmemobj_tx_xadd_range_direct(p, sizeof(*(p)), flags)
114 #define TX_XADD_FIELD_DIRECT(p, field, flags)\
115 pmemobj_tx_xadd_range_direct(&(p)->field, sizeof((p)->field), flags)
118 ((TOID(t))pmemobj_tx_alloc(sizeof(t), TOID_TYPE_NUM(t)))
120 #define TX_ALLOC(t, size)\
121 ((TOID(t))pmemobj_tx_alloc(size, TOID_TYPE_NUM(t)))
124 ((TOID(t))pmemobj_tx_zalloc(sizeof(t), TOID_TYPE_NUM(t)))
126 #define TX_ZALLOC(t, size)\
127 ((TOID(t))pmemobj_tx_zalloc(size, TOID_TYPE_NUM(t)))
129 #define TX_XALLOC(t, size, flags)\
130 ((TOID(t))pmemobj_tx_xalloc(size, TOID_TYPE_NUM(t), flags))
132 /* XXX - not available when compiled with VC++ as C code (/TC) */
133 #if !defined(_MSC_VER) || defined(__cplusplus)
134 #define TX_REALLOC(o, size)\
135 ((__typeof__(o))pmemobj_tx_realloc((o).oid, size, TOID_TYPE_NUM_OF(o)))
137 #define TX_ZREALLOC(o, size)\
138 ((__typeof__(o))pmemobj_tx_zrealloc((o).oid, size, TOID_TYPE_NUM_OF(o)))
139 #endif /* !defined(_MSC_VER) || defined(__cplusplus) */
141 #define TX_STRDUP(s, type_num)\
142 pmemobj_tx_strdup(s, type_num)
144 #define TX_XSTRDUP(s, type_num, flags)\
145 pmemobj_tx_xstrdup(s, type_num, flags)
147 #define TX_WCSDUP(s, type_num)\
148 pmemobj_tx_wcsdup(s, type_num)
150 #define TX_XWCSDUP(s, type_num, flags)\
151 pmemobj_tx_xwcsdup(s, type_num, flags)
154 pmemobj_tx_free((o).oid)
156 #define TX_XFREE(o, flags)\
157 pmemobj_tx_xfree((o).oid, flags)
159 #define TX_SET(o, field, value) (\
160 TX_ADD_FIELD(o, field),\
161 D_RW(o)->field = (value))
163 #define TX_SET_DIRECT(p, field, value) (\
164 TX_ADD_FIELD_DIRECT(p, field),\
165 (p)->field = (value))
168 TX_MEMCPY(void *dest
, const void *src
, size_t num
)
170 pmemobj_tx_add_range_direct(dest
, num
);
171 return memcpy(dest
, src
, num
);
175 TX_MEMSET(void *dest
, int c
, size_t num
)
177 pmemobj_tx_add_range_direct(dest
, num
);
178 return memset(dest
, c
, num
);
185 #endif /* libpmemobj/tx.h */