PMDK C++ bindings  1.6.1
This is the C++ bindings documentation for PMDK's libpmemobj.
make_persistent_array_atomic.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2019, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
40 #ifndef LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP
41 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP
42 
50 #include <libpmemobj/atomic_base.h>
51 
52 namespace pmem
53 {
54 
55 namespace obj
56 {
57 
73 template <typename T>
74 void
76  pool_base &pool, typename detail::pp_if_array<T>::type &ptr,
77  std::size_t N,
79 {
80  typedef typename detail::pp_array_type<T>::type I;
81 
82  auto ret = pmemobj_xalloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
83  detail::type_num<I>(), flag.value,
84  &detail::array_constructor<I>,
85  static_cast<void *>(&N));
86 
87  if (ret != 0)
88  throw std::bad_alloc();
89 }
90 
105 template <typename T>
106 void
108  pool_base &pool, typename detail::pp_if_size_array<T>::type &ptr,
110 {
111  typedef typename detail::pp_array_type<T>::type I;
112  std::size_t N = detail::pp_array_elems<T>::elems;
113 
114  auto ret = pmemobj_xalloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
115  detail::type_num<I>(), flag.value,
116  &detail::array_constructor<I>,
117  static_cast<void *>(&N));
118 
119  if (ret != 0)
120  throw std::bad_alloc();
121 }
122 
133 template <typename T>
134 void
135 delete_persistent_atomic(typename detail::pp_if_array<T>::type &ptr,
136  std::size_t)
137 {
138  if (ptr == nullptr)
139  return;
140 
141  /* we CAN'T call destructor */
142  pmemobj_free(ptr.raw_ptr());
143 }
144 
154 template <typename T>
155 void
156 delete_persistent_atomic(typename detail::pp_if_size_array<T>::type &ptr)
157 {
158  if (ptr == nullptr)
159  return;
160 
161  /* we CAN'T call destructor */
162  pmemobj_free(ptr.raw_ptr());
163 }
164 
165 } /* namespace obj */
166 
167 } /* namespace pmem */
168 
169 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP */
common.hpp
Commonly used functionality.
pexceptions.hpp
Custom exceptions.
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:135
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::allocation_flag_atomic
Type of flag which can be passed to make_persistent_atomic.
Definition: allocation_flag.hpp:123
pmem::obj::pool
PMEMobj pool class.
Definition: pool.hpp:431
pmem::obj::allocation_flag_atomic::none
static allocation_flag_atomic none()
Do not change allocator behaviour.
Definition: allocation_flag.hpp:144
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:67
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:75