PMDK C++ bindings  1.11.1
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-2020, Intel Corporation */
3 
11 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP
12 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP
13 
21 #include <libpmemobj++/pool.hpp>
22 #include <libpmemobj/atomic_base.h>
23 
24 #include <tuple>
25 
26 namespace pmem
27 {
28 
29 namespace obj
30 {
31 
48 template <typename T, typename... Args>
49 void
52  allocation_flag_atomic flag, Args &&... args)
53 {
54  auto arg_pack = std::forward_as_tuple(std::forward<Args>(args)...);
55  auto ret = pmemobj_xalloc(
56  pool.handle(), ptr.raw_ptr(), sizeof(T), detail::type_num<T>(),
57  flag.value,
58  &detail::obj_constructor<T, decltype(arg_pack), Args...>,
59  static_cast<void *>(&arg_pack));
60 
61  if (ret != 0)
62  throw std::bad_alloc();
63 }
64 
80 template <typename T, typename... Args>
81 typename std::enable_if<!detail::is_first_arg_same<allocation_flag_atomic,
82  Args...>::value>::type
85  Args &&... args)
86 {
87  make_persistent_atomic<T>(pool, ptr, allocation_flag_atomic::none(),
88  std::forward<Args>(args)...);
89 }
90 
101 template <typename T>
102 void
104  typename detail::pp_if_not_array<T>::type &ptr) noexcept
105 {
106  if (ptr == nullptr)
107  return;
108 
109  /* we CAN'T call the destructor */
110  pmemobj_free(ptr.raw_ptr());
111 }
112 
113 } /* namespace obj */
114 
115 } /* namespace pmem */
116 
117 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP */
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
make_persistent_array_atomic.hpp
Atomic persistent_ptr allocation functions for arrays.
common.hpp
Commonly used functionality.
pexceptions.hpp
Custom exceptions.
check_persistent_ptr_array.hpp
Compile time type check for make_persistent.
make_atomic_impl.hpp
Implementation details of atomic allocation and construction.
pmem::obj::delete_persistent_atomic
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:106
pmem::obj::allocation_flag_atomic
Type of flag which can be passed to make_persistent_atomic.
Definition: allocation_flag.hpp:94
pool.hpp
C++ pmemobj pool.
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:152
pmem::obj::pool
PMEMobj pool class.
Definition: pool.hpp:462
pmem::obj::allocation_flag_atomic::none
static allocation_flag_atomic none()
Do not change allocator behaviour.
Definition: allocation_flag.hpp:115
variadic.hpp
Helper functionality for handling variadic templates.
allocation_flag.hpp
allocation_flag - defines flags which can be passed to make_persistent
pmem::obj::pool_base
The non-template pool base class.
Definition: pool.hpp:46
pmem::obj::make_persistent_atomic
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:46