9 #ifndef LIBPMEMOBJ_CPP_COMMON_HPP
10 #define LIBPMEMOBJ_CPP_COMMON_HPP
13 #include <libpmemobj/tx_base.h>
22 #if defined(__GNUC__) || defined(__clang__)
23 #define POBJ_CPP_DEPRECATED __attribute__((deprecated))
24 #elif defined(_MSC_VER)
25 #define POBJ_CPP_DEPRECATED __declspec(deprecated)
27 #define POBJ_CPP_DEPRECATED
30 #if LIBPMEMOBJ_CPP_VG_ENABLED
31 #undef LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
32 #undef LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
33 #undef LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
34 #undef LIBPMEMOBJ_CPP_VG_DRD_ENABLED
36 #define LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED 1
37 #define LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED 1
38 #define LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED 1
39 #define LIBPMEMOBJ_CPP_VG_DRD_ENABLED 1
42 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED || \
43 LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED || \
44 LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED || LIBPMEMOBJ_CPP_VG_DRD_ENABLED
45 #define LIBPMEMOBJ_CPP_ANY_VG_TOOL_ENABLED 1
48 #if LIBPMEMOBJ_CPP_ANY_VG_TOOL_ENABLED
52 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
53 #include <pmemcheck.h>
56 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
60 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
64 #if LIBPMEMOBJ_CPP_VG_DRD_ENABLED
68 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
70 #define LIBPMEMOBJ_CPP_ANNOTATE_HAPPENS_BEFORE(order, ptr) \
71 if (order == std::memory_order_release || \
72 order == std::memory_order_acq_rel || \
73 order == std::memory_order_seq_cst) { \
74 ANNOTATE_HAPPENS_BEFORE(ptr); \
77 #define LIBPMEMOBJ_CPP_ANNOTATE_HAPPENS_AFTER(order, ptr) \
78 if (order == std::memory_order_consume || \
79 order == std::memory_order_acquire || \
80 order == std::memory_order_acq_rel || \
81 order == std::memory_order_seq_cst) { \
82 ANNOTATE_HAPPENS_AFTER(ptr); \
86 #define LIBPMEMOBJ_CPP_ANNOTATE_HAPPENS_BEFORE(order, ptr)
87 #define LIBPMEMOBJ_CPP_ANNOTATE_HAPPENS_AFTER(order, ptr)
98 #if !defined(LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY)
99 #if !defined(__clang__) && defined(__GNUG__) && __GNUC__ < 5
100 #define LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY 1
102 #define LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY 0
106 #if LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY
107 #define LIBPMEMOBJ_CPP_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
109 #define LIBPMEMOBJ_CPP_IS_TRIVIALLY_COPYABLE(T) \
110 std::is_trivially_copyable<T>::value
129 template <
typename T>
130 class persistent_ptr;
139 namespace experimental
153 #if defined(__x86_64) || defined(_M_X64) || defined(__aarch64__) || \
155 static constexpr
size_t CACHELINE_SIZE = 64ULL;
156 #elif defined(__PPC64__)
157 static constexpr
size_t CACHELINE_SIZE = 128ULL;
159 #error unable to recognize architecture at compile time
174 template <
typename T>
176 conditional_add_to_tx(
const T *that, std::size_t count = 1, uint64_t flags = 0)
181 if (pmemobj_tx_stage() != TX_STAGE_WORK)
185 if (!pmemobj_pool_by_ptr(that))
188 if (pmemobj_tx_xadd_range_direct(that,
sizeof(*that) * count, flags)) {
191 "Could not add object(s) to the transaction.")
192 .with_pmemobj_errormsg();
195 "Could not add object(s) to the transaction.")
196 .with_pmemobj_errormsg();
203 template <
typename T>
207 return typeid(T).hash_code();
248 _BitScanReverse64(&j, x);
249 return static_cast<int>(j);
251 #elif __GNUC__ || __clang__
256 return 8 * int(
sizeof(x)) - __builtin_clzll(x) - 1;
269 static const int table[64] = {
270 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3, 61,
271 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4, 62,
272 57, 46, 52, 38, 26, 32, 41, 50, 36, 17, 19, 29, 10, 13, 21, 56,
273 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5, 63};
275 return table[(x * 0x03f6eaf2cd271461) >> 58];
282 static inline uint8_t
283 mssb_index64(
unsigned long long value)
285 return ((uint8_t)(63 - __builtin_clzll(value)));
289 static inline uint8_t
290 mssb_index(
unsigned int value)
292 return ((uint8_t)(31 - __builtin_clz(value)));
297 static __inline uint8_t
298 mssb_index(
unsigned long value)
301 _BitScanReverse(&ret, value);
305 static __inline uint8_t
306 mssb_index64(uint64_t value)
309 _BitScanReverse64(&ret, value);
315 static constexpr
size_t
316 align_up(
size_t size,
size_t align)
318 return ((size) + (align)-1) & ~((align)-1);
321 static constexpr
size_t
322 align_down(
size_t size,
size_t align)
324 return (size) & ~((align)-1);
Custom transaction error class.
Definition: pexceptions.hpp:81
Custom out of memory error class.
Definition: pexceptions.hpp:138
uint64_t next_pow_2(uint64_t v)
Round up to the next lowest power of 2.
Definition: common.hpp:214
Persistent memory namespace.
Definition: allocation_flag.hpp:15