38 #ifndef LIBPMEMOBJ_CPP_COMMON_HPP
39 #define LIBPMEMOBJ_CPP_COMMON_HPP
42 #include <libpmemobj/tx_base.h>
51 #if defined(__GNUC__) || defined(__clang__)
52 #define POBJ_CPP_DEPRECATED __attribute__((deprecated))
53 #elif defined(_MSC_VER)
54 #define POBJ_CPP_DEPRECATED __declspec(deprecated)
56 #define POBJ_CPP_DEPRECATED
59 #if LIBPMEMOBJ_CPP_VG_ENABLED
60 #undef LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
61 #undef LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
62 #undef LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
63 #undef LIBPMEMOBJ_CPP_VG_DRD_ENABLED
65 #define LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED 1
66 #define LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED 1
67 #define LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED 1
68 #define LIBPMEMOBJ_CPP_VG_DRD_ENABLED 1
71 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED || \
72 LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED || \
73 LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED || LIBPMEMOBJ_CPP_VG_DRD_ENABLED
74 #define LIBPMEMOBJ_CPP_ANY_VG_TOOL_ENABLED 1
77 #if LIBPMEMOBJ_CPP_ANY_VG_TOOL_ENABLED
81 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
82 #include <pmemcheck.h>
85 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
89 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
93 #if LIBPMEMOBJ_CPP_VG_DRD_ENABLED
104 #if !defined(LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY)
105 #if !defined(__clang__) && defined(__GNUG__) && __GNUC__ < 5
106 #define LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY 1
108 #define LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY 0
112 #if LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY
113 #define LIBPMEMOBJ_CPP_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
115 #define LIBPMEMOBJ_CPP_IS_TRIVIALLY_COPYABLE(T) \
116 std::is_trivially_copyable<T>::value
136 template <
typename T>
137 class persistent_ptr;
146 namespace experimental
172 template <
typename T>
174 conditional_add_to_tx(
const T *that, std::size_t count = 1, uint64_t flags = 0)
179 if (pmemobj_tx_stage() != TX_STAGE_WORK)
183 if (!pmemobj_pool_by_ptr(that))
186 if (pmemobj_tx_xadd_range_direct(that,
sizeof(*that) * count, flags)) {
189 "Could not add object(s) to the transaction.")
190 .with_pmemobj_errormsg();
193 "Could not add object(s) to the transaction.")
194 .with_pmemobj_errormsg();
201 template <
typename T>
205 return typeid(T).hash_code();
246 _BitScanReverse64(&j, x);
247 return static_cast<int>(j);
249 #elif __GNUC__ || __clang__
254 return 8 * int(
sizeof(x)) - __builtin_clzll(x) - 1;
267 static const int table[64] = {
268 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3, 61,
269 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4, 62,
270 57, 46, 52, 38, 26, 32, 41, 50, 36, 17, 19, 29, 10, 13, 21, 56,
271 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5, 63};
273 return table[(x * 0x03f6eaf2cd271461) >> 58];