PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
make_persistent_atomic.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2016-2021, Intel Corporation */
3 
12 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP
13 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP
14 
22 #include <libpmemobj++/pool.hpp>
23 #include <libpmemobj/atomic_base.h>
24 
25 #include <tuple>
26 
27 namespace pmem
28 {
29 
30 namespace obj
31 {
32 
50 template <typename T, typename... Args>
51 void
54  allocation_flag_atomic flag, Args &&... args)
55 {
56  auto arg_pack = std::forward_as_tuple(std::forward<Args>(args)...);
57  auto ret = pmemobj_xalloc(
58  pool.handle(), ptr.raw_ptr(), sizeof(T), detail::type_num<T>(),
59  flag.value,
60  &detail::obj_constructor<T, decltype(arg_pack), Args...>,
61  static_cast<void *>(&arg_pack));
62 
63  if (ret != 0)
64  throw std::bad_alloc();
65 }
66 
83 template <typename T, typename... Args>
84 typename std::enable_if<!detail::is_first_arg_same<allocation_flag_atomic,
85  Args...>::value>::type
88  Args &&... args)
89 {
90  make_persistent_atomic<T>(pool, ptr, allocation_flag_atomic::none(),
91  std::forward<Args>(args)...);
92 }
93 
105 template <typename T>
106 void
108  typename detail::pp_if_not_array<T>::type &ptr) noexcept
109 {
110  if (ptr == nullptr)
111  return;
112 
113  /* we CAN'T call the destructor */
114  pmemobj_free(ptr.raw_ptr());
115 }
116 
117 } /* namespace obj */
118 
119 } /* namespace pmem */
120 
121 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP */
allocation_flag - defines flags which can be passed to make_persistent
Compile time type check for make_persistent.
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:164
Persistent pointer class.
Definition: persistent_ptr.hpp:153
The non-template pool base class.
Definition: pool.hpp:51
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:395
PMEMobj pool class.
Definition: pool.hpp:482
Commonly used functionality.
void delete_persistent_atomic(typename detail::pp_if_array< T >::type &ptr, std::size_t)
Atomically deallocate an array of objects.
Definition: make_persistent_array_atomic.hpp:110
void make_persistent_atomic(pool_base &pool, typename detail::pp_if_array< T >::type &ptr, std::size_t N, allocation_flag_atomic flag=allocation_flag_atomic::none())
Atomically allocate an array of objects.
Definition: make_persistent_array_atomic.hpp:48
Implementation details of atomic allocation and construction.
persistent_ptr atomic allocation functions for arrays.
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Custom pmem exceptions.
C++ pmemobj pool.
Type of flag which can be passed to make_persistent_atomic.
Definition: allocation_flag.hpp:94
static allocation_flag_atomic none()
Do not change allocator behaviour.
Definition: allocation_flag.hpp:115
Helper functionality for handling variadic templates.