PMDK C++ bindings  1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
make_atomic_impl.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2016-2019, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_MAKE_ATOMIC_IMPL_HPP
10 #define LIBPMEMOBJ_CPP_MAKE_ATOMIC_IMPL_HPP
11 
12 #include <cstddef>
13 #include <new>
14 
18 
19 namespace pmem
20 {
21 
22 namespace detail
23 {
24 
25 /*
26  * C-style function called by the allocator.
27  *
28  * The arg is a tuple containing constructor parameters.
29  */
30 template <typename T, typename Tuple, typename... Args>
31 int
32 obj_constructor(PMEMobjpool *pop, void *ptr, void *arg)
33 {
34  auto ret = c_style_construct<T, Tuple, Args...>(ptr, arg);
35 
36  if (ret != 0)
37  return -1;
38 
39  pmemobj_persist(pop, ptr, sizeof(T));
40 
41  return 0;
42 }
43 
44 /*
45  * Constructor used for atomic array allocations.
46  *
47  * Returns -1 if an exception was thrown during T's construction,
48  * 0 otherwise.
49  */
50 template <typename T>
51 int
52 array_constructor(PMEMobjpool *pop, void *ptr, void *arg)
53 {
54  std::size_t N = *static_cast<std::size_t *>(arg);
55 
56  T *tptr = static_cast<T *>(ptr);
57  try {
58  for (std::size_t i = 0; i < N; ++i)
59  detail::create<T>(tptr + i);
60  } catch (...) {
61  return -1;
62  }
63 
64  pmemobj_persist(pop, ptr, sizeof(T) * N);
65 
66  return 0;
67 }
68 
69 } /* namespace detail */
70 
71 } /* namespace pmem */
72 
73 #endif /* LIBPMEMOBJ_CPP_MAKE_ATOMIC_IMPL_HPP */
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
integer_sequence.hpp
Create c++14 style index sequence.
array_traits.hpp
Common array traits.
life.hpp
Functions for destroying arrays.