9 #ifndef LIBPMEMOBJ_CPP_ATOMIC_PERSISTENT_AWARE_PTR_HPP
10 #define LIBPMEMOBJ_CPP_ATOMIC_PERSISTENT_AWARE_PTR_HPP
26 namespace experimental
42 template <
typename T,
typename ReadOptimized>
46 std::atomic<std::ptrdiff_t>>;
48 std::atomic<std::ptrdiff_t>>;
50 static constexpr uintptr_t IS_DIRTY = 1;
85 template <
typename OPT = ReadOptimized>
86 typename std::enable_if<std::is_same<OPT, std::true_type>::value>::type
88 std::memory_order order = std::memory_order_seq_cst) noexcept
90 auto dirty_desired = mark_dirty(desired);
91 ptr.store(dirty_desired, order);
93 ptr.compare_exchange_strong(dirty_desired, clear_dirty(desired),
97 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
98 VALGRIND_PMC_DO_FLUSH(&ptr,
sizeof(ptr));
108 template <
typename OPT = ReadOptimized>
109 typename std::enable_if<!std::is_same<OPT, std::true_type>::value>::type
111 std::memory_order order = std::memory_order_seq_cst) noexcept
113 ptr.store(mark_dirty(desired), order);
121 template <
typename OPT = ReadOptimized>
122 typename std::enable_if<std::is_same<OPT, std::true_type>::value,
124 load(std::memory_order order = std::memory_order_seq_cst) noexcept
129 auto val = ptr.load(order);
133 return clear_dirty(val);
141 template <
typename OPT = ReadOptimized>
142 typename std::enable_if<!std::is_same<OPT, std::true_type>::value,
144 load(std::memory_order order = std::memory_order_seq_cst) noexcept
150 auto val = ptr.load(order);
153 auto clear_val = clear_dirty(val);
154 ptr.compare_exchange_strong(val, clear_val, order);
155 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
156 VALGRIND_PMC_DO_FLUSH(&ptr,
sizeof(ptr));
160 return clear_dirty(val);
164 is_lock_free() const noexcept
166 return ptr.is_lock_free();
205 reinterpret_cast<uintptr_t
>(ptr.
get()) | IS_DIRTY;
206 return value_type{
reinterpret_cast<T *
>(dirty_ptr)};
210 clear_dirty(value_type ptr)
const
213 reinterpret_cast<uintptr_t
>(ptr.get()) & ~IS_DIRTY;
214 return value_type{
reinterpret_cast<T *
>(clear_ptr)};
218 is_dirty(value_type ptr)
const
220 return reinterpret_cast<uintptr_t
>(ptr.get()) & IS_DIRTY;
223 std::atomic<self_relative_ptr<T>> ptr;
Atomic backoff, for time delay.
Atomic specialization for self_relative_ptr.
Static class accessor to self_relative_ptr_base.
Definition: self_relative_ptr_base_impl.hpp:296
Persistent self-relative pointer class.
Definition: self_relative_ptr.hpp:82
element_type * get() const noexcept
Get the direct pointer.
Definition: self_relative_ptr.hpp:197
typename base_type::difference_type difference_type
The self_relative_ptr difference type.
Definition: self_relative_ptr.hpp:100
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:280
Commonly used functionality.
pool_base pool_by_vptr(const T *that)
Retrieve pool handle for the given pointer.
Definition: utils.hpp:32
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent self-relative smart pointer.
Base class for self_relative_ptr.
Atomic specialization of a persistent ptr (self_relative_ptr) that manages its persistence by itself.
Definition: atomic_persistent_aware_ptr.hpp:43
std::enable_if< std::is_same< OPT, std::true_type >::value, value_type >::type load(std::memory_order order=std::memory_order_seq_cst) noexcept
Read-optimized load.
Definition: atomic_persistent_aware_ptr.hpp:124
atomic_persistent_aware_ptr & operator=(const atomic_persistent_aware_ptr &)=delete
Deleted assignment operator.
std::enable_if<!std::is_same< OPT, std::true_type >::value, value_type >::type load(std::memory_order order=std::memory_order_seq_cst) noexcept
Write-optimized load flushes the data.
Definition: atomic_persistent_aware_ptr.hpp:144
std::enable_if<!std::is_same< OPT, std::true_type >::value >::type store(value_type desired, std::memory_order order=std::memory_order_seq_cst) noexcept
Write-optimized store relies on a consequent load to do the flush.
Definition: atomic_persistent_aware_ptr.hpp:110
std::enable_if< std::is_same< OPT, std::true_type >::value >::type store(value_type desired, std::memory_order order=std::memory_order_seq_cst) noexcept
Read-optimized store does the flush already in the store function.
Definition: atomic_persistent_aware_ptr.hpp:87
value_type operator=(value_type desired) noexcept
Assignment operator.
Definition: atomic_persistent_aware_ptr.hpp:188
atomic_persistent_aware_ptr(const atomic_persistent_aware_ptr &)=delete
Deleted copy constructor.
atomic_persistent_aware_ptr(value_type value)
Constructors.
Definition: atomic_persistent_aware_ptr.hpp:68
C++ pmemobj transactions.