PMDK C++ bindings 1.2.0
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-2017, 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 PMEMOBJ_MAKE_PERSISTENT_ATOMIC_HPP
41#define PMEMOBJ_MAKE_PERSISTENT_ATOMIC_HPP
42
47#include "libpmemobj++/pool.hpp"
48#include "libpmemobj/atomic_base.h"
49
50#include <tuple>
51
52namespace pmem
53{
54
55namespace obj
56{
57
73template <typename T, typename... Args>
74void
77 Args &&... args)
78{
79 std::tuple<Args &...> arg_pack{args...};
80 auto ret = pmemobj_alloc(pool.get_handle(), ptr.raw_ptr(), sizeof(T),
81 detail::type_num<T>(),
82 &detail::obj_constructor<T, Args...>,
83 static_cast<void *>(&arg_pack));
84
85 if (ret != 0)
86 throw std::bad_alloc();
87}
88
99template <typename T>
100void
102 typename detail::pp_if_not_array<T>::type &ptr) noexcept
103{
104 if (ptr == nullptr)
105 return;
106
107 /* we CAN'T call the destructor */
108 pmemobj_free(ptr.raw_ptr());
109}
110
111} /* namespace obj */
112
113} /* namespace pmem */
114
115#endif /* PMEMOBJ_MAKE_PERSISTENT_ATOMIC_HPP */
Compile time type check for make_persistent.
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:309
Persistent pointer class.
Definition: persistent_ptr.hpp:102
The non-template pool base class.
Definition: pool.hpp:65
PMEMobj pool class.
Definition: pool.hpp:423
Commonly used functionality.
Implementation details of atomic allocation and construction.
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
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
Custom exceptions.
C++ pmemobj pool.