PMDK C++ bindings  1.7
This is the C++ bindings documentation for PMDK's libpmemobj.
temp_value.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 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 
38 #ifndef LIBPMEMOBJ_CPP_TEMP_VALUE_HPP
39 #define LIBPMEMOBJ_CPP_TEMP_VALUE_HPP
40 
42 
43 namespace pmem
44 {
45 
46 namespace detail
47 {
48 
54 #ifndef LIBPMEMOBJ_CPP_MAX_STACK_ALLOC_SIZE
55 #define LIBPMEMOBJ_CPP_MAX_STACK_ALLOC_SIZE 64 * (1 << 10)
56 #endif
57 
63 template <typename T, bool NoExcept, typename Enable = void>
64 struct temp_value;
65 
71 template <typename T, bool NoExcept>
72 struct temp_value<
73  T, NoExcept,
74  typename std::enable_if<NoExcept &&
75  (sizeof(T) <
76  LIBPMEMOBJ_CPP_MAX_STACK_ALLOC_SIZE)>::type> {
77  template <typename... Args>
78  temp_value(Args &&... args) noexcept : t(std::forward<Args>(args)...)
79  {
80  }
81 
82  T &
83  get() noexcept
84  {
85  return t;
86  }
87 
88  T t;
89 };
90 
96 template <typename T, bool NoExcept>
97 struct temp_value<
98  T, NoExcept,
99  typename std::enable_if<!NoExcept ||
100  (sizeof(T) >=
101  LIBPMEMOBJ_CPP_MAX_STACK_ALLOC_SIZE)>::type> {
102  template <typename... Args>
103  temp_value(Args &&... args)
104  {
105  ptr = pmem::obj::make_persistent<T>(
106  std::forward<Args>(args)...);
107  }
108 
109  ~temp_value()
110  {
111  pmem::obj::delete_persistent<T>(ptr);
112  }
113 
114  T &
115  get()
116  {
117  return *ptr;
118  }
119 
121 };
122 
123 } /* namespace detail */
124 
125 } /* namespace pmem */
126 
127 #endif /* LIBPMEMOBJ_CPP_TEMP_VALUE_HPP */
make_persistent.hpp
Persistent_ptr transactional allocation functions for objects.
pmem::detail::temp_value
Template class for caching objects based on constructor's variadic template arguments and LIBPMEMOBJ_...
Definition: temp_value.hpp:64
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:132
std
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: concurrent_hash_map.hpp:75