PMDK C++ bindings 1.13.0
This is the C++ bindings documentation for PMDK's libpmemobj.
Loading...
Searching...
No Matches
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
19namespace pmem
20{
21
22namespace detail
23{
24
25/*
26 * C-style function called by the allocator.
27 *
28 * The arg is a tuple containing constructor parameters.
29 */
30template <typename T, typename Tuple, typename... Args>
31int
32obj_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 */
50template <typename T>
51int
52array_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 */
Common array traits.
Create c++14 style index sequence.
Functions for destroying arrays.
Persistent memory namespace.
Definition: allocation_flag.hpp:15