PMDK C++ bindings  1.5.2
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-2018, 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 
48 #include <libpmemobj/atomic_base.h>
49 
50 namespace pmem
51 {
52 
53 namespace obj
54 {
55 
70 template <typename T>
71 void
73  typename detail::pp_if_array<T>::type &ptr,
74  std::size_t N)
75 {
76  typedef typename detail::pp_array_type<T>::type I;
77 
78  auto ret = pmemobj_alloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
79  detail::type_num<I>(),
80  &detail::array_constructor<I>,
81  static_cast<void *>(&N));
82 
83  if (ret != 0)
84  throw std::bad_alloc();
85 }
86 
100 template <typename T>
101 void
103  typename detail::pp_if_size_array<T>::type &ptr)
104 {
105  typedef typename detail::pp_array_type<T>::type I;
106  std::size_t N = detail::pp_array_elems<T>::elems;
107 
108  auto ret = pmemobj_alloc(pool.handle(), ptr.raw_ptr(), sizeof(I) * N,
109  detail::type_num<I>(),
110  &detail::array_constructor<I>,
111  static_cast<void *>(&N));
112 
113  if (ret != 0)
114  throw std::bad_alloc();
115 }
116 
127 template <typename T>
128 void
129 delete_persistent_atomic(typename detail::pp_if_array<T>::type &ptr,
130  std::size_t)
131 {
132  if (ptr == nullptr)
133  return;
134 
135  /* we CAN'T call destructor */
136  pmemobj_free(ptr.raw_ptr());
137 }
138 
148 template <typename T>
149 void
150 delete_persistent_atomic(typename detail::pp_if_size_array<T>::type &ptr)
151 {
152  if (ptr == nullptr)
153  return;
154 
155  /* we CAN'T call destructor */
156  pmemobj_free(ptr.raw_ptr());
157 }
158 
159 } /* namespace obj */
160 
161 } /* namespace pmem */
162 
163 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ARRAY_ATOMIC_HPP */
common.hpp
Commonly used functionality.
pmem::obj::make_persistent_atomic
void make_persistent_atomic(pool_base &pool, typename detail::pp_if_array< T >::type &ptr, std::size_t N)
Atomically allocate an array of objects.
Definition: make_persistent_array_atomic.hpp:72
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:129
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::pool
PMEMobj pool class.
Definition: pool.hpp:430
array_traits.hpp
Common array traits.
pmem::obj::pool_base
The non-template pool base class.
Definition: pool.hpp:66