PMDK C++ bindings  1.8.2
This is the C++ bindings documentation for PMDK's libpmemobj.
make_persistent_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_ATOMIC_HPP
41 #define LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP
42 
50 #include <libpmemobj++/pool.hpp>
51 #include <libpmemobj/atomic_base.h>
52 
53 #include <tuple>
54 
55 namespace pmem
56 {
57 
58 namespace obj
59 {
60 
77 template <typename T, typename... Args>
78 void
81  allocation_flag_atomic flag, Args &&... args)
82 {
83  auto arg_pack = std::forward_as_tuple(std::forward<Args>(args)...);
84  auto ret = pmemobj_xalloc(
85  pool.handle(), ptr.raw_ptr(), sizeof(T), detail::type_num<T>(),
86  flag.value,
87  &detail::obj_constructor<T, decltype(arg_pack), Args...>,
88  static_cast<void *>(&arg_pack));
89 
90  if (ret != 0)
91  throw std::bad_alloc();
92 }
93 
109 template <typename T, typename... Args>
110 typename std::enable_if<!detail::is_first_arg_same<allocation_flag_atomic,
111  Args...>::value>::type
113  typename detail::pp_if_not_array<T>::type &ptr,
114  Args &&... args)
115 {
116  make_persistent_atomic<T>(pool, ptr, allocation_flag_atomic::none(),
117  std::forward<Args>(args)...);
118 }
119 
130 template <typename T>
131 void
133  typename detail::pp_if_not_array<T>::type &ptr) noexcept
134 {
135  if (ptr == nullptr)
136  return;
137 
138  /* we CAN'T call the destructor */
139  pmemobj_free(ptr.raw_ptr());
140 }
141 
142 } /* namespace obj */
143 
144 } /* namespace pmem */
145 
146 #endif /* LIBPMEMOBJ_CPP_MAKE_PERSISTENT_ATOMIC_HPP */
Type of flag which can be passed to make_persistent_atomic.
Definition: allocation_flag.hpp:123
Persistent pointer class.
Definition: common.hpp:125
The non-template pool base class.
Definition: pool.hpp:67
PMEMobj pool class.
Definition: persistent_ptr.hpp:59
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:403
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
Commonly used functionality.
Custom exceptions.
Compile time type check for make_persistent.
Implementation details of atomic allocation and construction.
Helper functionality for handling variadic templates.
static allocation_flag_atomic none()
Do not change allocator behaviour.
Definition: allocation_flag.hpp:144
allocation_flag - defines flags which can be passed to make_persistent
Atomic persistent_ptr allocation functions for arrays.
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:317
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:43
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
C++ pmemobj pool.