PMDK C++ bindings  1.10
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-2019, Intel Corporation */
3 
11 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP
12 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP
13 
21 #include <libpmemobj/atomic_base.h>
22 
23 namespace pmem
24 {
25 
26 namespace obj
27 {
28 
44 template <typename T>
45 void
47  pool_base &pool, typename detail::pp_if_array<T>::type &ptr,
48  std::size_t N,
50 {
51  typedef typename detail::pp_array_type<T>::type I;
52 
53  auto ret = pmemobj_xalloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
54  detail::type_num<I>(), flag.value,
55  &detail::array_constructor<I>,
56  static_cast<void *>(&N));
57 
58  if (ret != 0)
59  throw std::bad_alloc();
60 }
61 
76 template <typename T>
77 void
79  pool_base &pool, typename detail::pp_if_size_array<T>::type &ptr,
81 {
82  typedef typename detail::pp_array_type<T>::type I;
83  std::size_t N = detail::pp_array_elems<T>::elems;
84 
85  auto ret = pmemobj_xalloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
86  detail::type_num<I>(), flag.value,
87  &detail::array_constructor<I>,
88  static_cast<void *>(&N));
89 
90  if (ret != 0)
91  throw std::bad_alloc();
92 }
93 
104 template <typename T>
105 void
106 delete_persistent_atomic(typename detail::pp_if_array<T>::type &ptr,
107  std::size_t)
108 {
109  if (ptr == nullptr)
110  return;
111 
112  /* we CAN'T call destructor */
113  pmemobj_free(ptr.raw_ptr());
114 }
115 
125 template <typename T>
126 void
127 delete_persistent_atomic(typename detail::pp_if_size_array<T>::type &ptr)
128 {
129  if (ptr == nullptr)
130  return;
131 
132  /* we CAN'T call destructor */
133  pmemobj_free(ptr.raw_ptr());
134 }
135 
136 } /* namespace obj */
137 
138 } /* namespace pmem */
139 
140 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP */
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
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
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
array_traits.hpp
Common array traits.
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