PMDK C++ bindings
1.12.1-rc1
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_DEFRAG_HPP
10 #define LIBPMEMOBJ_CPP_DEFRAG_HPP
12 #include <type_traits>
18 #include <libpmemobj/atomic_base.h>
19 #include <libpmemobj/base.h>
26 using for_each_ptr_function = void (*)(obj::persistent_ptr_base &ptr);
29 using t_has_for_each_ptr =
typename std::enable_if<
30 std::is_same<decltype(std::declval<T>().for_each_ptr(
31 std::declval<for_each_ptr_function>())),
35 using t_is_defragmentable = supports<T, t_has_for_each_ptr>;
49 static constexpr
typename std::enable_if<detail::t_is_defragmentable<T>::value,
51 is_defragmentable() noexcept
63 static constexpr
typename std::enable_if<!detail::t_is_defragmentable<T>::value,
65 is_defragmentable() noexcept
110 template <
typename T>
111 typename std::enable_if<is_defragmentable<T>(),
void>::type
114 if (pmemobj_pool_by_ptr(&t) != pop.
handle())
115 throw std::runtime_error(
116 "object is not from the chosen pool");
119 this->container.push_back(&ptr);
138 template <
typename T,
typename = T>
139 typename std::enable_if<!is_defragmentable<T>(),
void>::type
142 if (pmemobj_pool_by_ptr(&t) != pop.
handle())
143 throw std::runtime_error(
144 "object is not from the chosen pool");
160 template <
typename T>
164 if (pmemobj_pool_by_oid(ptr.raw()) != pop.
handle())
165 throw std::runtime_error(
166 "persistent_ptr does not point to an object from the chosen pool");
168 this->container.push_back(&ptr);
190 pobj_defrag_result result = this->pop.
defrag(
191 this->container.data(), this->container.size());
197 std::vector<persistent_ptr_base *> container;
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Commonly used SFINAE helpers.
pobj_defrag_result defrag(persistent_ptr_base **ptrv, size_t oidcnt)
Starts defragmentation using selected pointers within this pool.
Definition: pool.hpp:423
Resides on pmem class.
Definition: p.hpp:35
Defrag class.
Definition: defrag.hpp:83
std::enable_if<!is_defragmentable< T >), void >::type add(T &t)
Specialization for non-defragmentable types.
Definition: defrag.hpp:140
defrag(pool_base p)
The only allowed ctor.
Definition: defrag.hpp:93
pobj_defrag_result run()
Starts defragmentation with previously stored pointers.
Definition: defrag.hpp:188
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:398
Persistent pointer class.
Definition: persistent_ptr.hpp:152
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
std::enable_if< is_defragmentable< T >), void >::type add(T &t)
Stores address of the referenced object to the defragmentation queue.
Definition: defrag.hpp:112
Base class for persistent_ptr.
The non-template pool base class.
Definition: pool.hpp:46
void add(persistent_ptr< T > &ptr)
Stores address of a persistent_ptr to the defragmentation queue.
Definition: defrag.hpp:162