PMDK C++ bindings
1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_DEFRAG_HPP
39 #define LIBPMEMOBJ_CPP_DEFRAG_HPP
41 #include <type_traits>
47 #include <libpmemobj/atomic_base.h>
48 #include <libpmemobj/base.h>
55 using for_each_ptr_function = void (*)(obj::persistent_ptr_base &ptr);
58 using t_has_for_each_ptr =
typename std::enable_if<
59 std::is_same<decltype(std::declval<T>().for_each_ptr(
60 std::declval<for_each_ptr_function>())),
64 using t_is_defragmentable = supports<T, t_has_for_each_ptr>;
78 static constexpr
typename std::enable_if<detail::t_is_defragmentable<T>::value,
80 is_defragmentable() noexcept
92 static constexpr
typename std::enable_if<!detail::t_is_defragmentable<T>::value,
94 is_defragmentable() noexcept
139 template <
typename T>
140 typename std::enable_if<is_defragmentable<T>(),
void>::type
143 if (pmemobj_pool_by_ptr(&t) != pop.
handle())
144 throw std::runtime_error(
145 "object is not from the chosen pool");
148 this->container.push_back(&ptr);
167 template <
typename T,
typename = T>
168 typename std::enable_if<!is_defragmentable<T>(),
void>::type
171 if (pmemobj_pool_by_ptr(&t) != pop.
handle())
172 throw std::runtime_error(
173 "object is not from the chosen pool");
189 template <
typename T>
193 if (pmemobj_pool_by_oid(ptr.raw()) != pop.
handle())
194 throw std::runtime_error(
195 "persistent_ptr does not point to an object from the chosen pool");
197 this->container.push_back(&ptr);
219 pobj_defrag_result result = this->pop.
defrag(
220 this->container.data(), this->container.size());
226 std::vector<persistent_ptr_base *> container;
Persistent memory namespace.
Definition: allocation_flag.hpp:44
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:452
Resides on pmem class.
Definition: p.hpp:64
Defrag class.
Definition: defrag.hpp:112
std::enable_if<!is_defragmentable< T >), void >::type add(T &t)
Specialization for non-defragmentable types.
Definition: defrag.hpp:169
defrag(pool_base p)
The only allowed ctor.
Definition: defrag.hpp:122
pobj_defrag_result run()
Starts defragmentation with previously stored pointers.
Definition: defrag.hpp:217
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:427
Persistent pointer class.
Definition: persistent_ptr.hpp:212
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:71
std::enable_if< is_defragmentable< T >), void >::type add(T &t)
Stores address of the referenced object to the defragmentation queue.
Definition: defrag.hpp:141
Base class for persistent_ptr.
The non-template pool base class.
Definition: pool.hpp:75
void add(persistent_ptr< T > &ptr)
Stores address of a persistent_ptr to the defragmentation queue.
Definition: defrag.hpp:191