PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
make_persistent_array_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_ARRAY_ATOMIC_HPP
13 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP
14 
22 #include <libpmemobj/atomic_base.h>
23 
24 namespace pmem
25 {
26 
27 namespace obj
28 {
29 
46 template <typename T>
47 void
49  pool_base &pool, typename detail::pp_if_array<T>::type &ptr,
50  std::size_t N,
52 {
53  typedef typename detail::pp_array_type<T>::type I;
54 
55  auto ret = pmemobj_xalloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
56  detail::type_num<I>(), flag.value,
57  &detail::array_constructor<I>,
58  static_cast<void *>(&N));
59 
60  if (ret != 0)
61  throw std::bad_alloc();
62 }
63 
79 template <typename T>
80 void
82  pool_base &pool, typename detail::pp_if_size_array<T>::type &ptr,
84 {
85  typedef typename detail::pp_array_type<T>::type I;
86  std::size_t N = detail::pp_array_elems<T>::elems;
87 
88  auto ret = pmemobj_xalloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
89  detail::type_num<I>(), flag.value,
90  &detail::array_constructor<I>,
91  static_cast<void *>(&N));
92 
93  if (ret != 0)
94  throw std::bad_alloc();
95 }
96 
108 template <typename T>
109 void
110 delete_persistent_atomic(typename detail::pp_if_array<T>::type &ptr,
111  std::size_t)
112 {
113  if (ptr == nullptr)
114  return;
115 
116  /* we CAN'T call destructor */
117  pmemobj_free(ptr.raw_ptr());
118 }
119 
130 template <typename T>
131 void
132 delete_persistent_atomic(typename detail::pp_if_size_array<T>::type &ptr)
133 {
134  if (ptr == nullptr)
135  return;
136 
137  /* we CAN'T call destructor */
138  pmemobj_free(ptr.raw_ptr());
139 }
140 
141 } /* namespace obj */
142 
143 } /* namespace pmem */
144 
145 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP */
allocation_flag - defines flags which can be passed to make_persistent
Common array traits.
Compile time type check for make_persistent.
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 memory namespace.
Definition: allocation_flag.hpp:15
Custom pmem exceptions.
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.