PMDK C++ bindings
1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_POOL_HPP
10 #define LIBPMEMOBJ_CPP_POOL_HPP
18 #include <unordered_map>
27 #include <libpmemobj/atomic_base.h>
28 #include <libpmemobj/pool_base.h>
62 explicit pool_base(pmemobjpool *cpop) noexcept : pop(cpop)
104 open(const std::
string &path, const std::
string &layout)
107 pmemobjpool *pop = pmemobj_openU(path.c_str(), layout.c_str());
109 pmemobjpool *pop = pmemobj_open(path.c_str(), layout.c_str());
113 .with_pmemobj_errormsg();
115 pmemobj_set_user_data(pop,
new detail::pool_data);
137 create(
const std::string &path,
const std::string &layout,
138 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
141 pmemobjpool *pop = pmemobj_createU(path.c_str(), layout.c_str(),
144 pmemobjpool *pop = pmemobj_create(path.c_str(), layout.c_str(),
149 .with_pmemobj_errormsg();
151 pmemobj_set_user_data(pop,
new detail::pool_data);
167 check(
const std::string &path,
const std::string &layout) noexcept
170 return pmemobj_checkU(path.c_str(), layout.c_str());
172 return pmemobj_check(path.c_str(), layout.c_str());
191 open(
const std::wstring &path,
const std::wstring &layout)
193 pmemobjpool *pop = pmemobj_openW(path.c_str(), layout.c_str());
196 .with_pmemobj_errormsg();
198 pmemobj_set_user_data(pop,
new detail::pool_data);
221 create(
const std::wstring &path,
const std::wstring &layout,
222 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
224 pmemobjpool *pop = pmemobj_createW(path.c_str(), layout.c_str(),
228 .with_pmemobj_errormsg();
230 pmemobj_set_user_data(pop,
new detail::pool_data);
247 check(
const std::wstring &path,
const std::wstring &layout) noexcept
249 return pmemobj_checkW(path.c_str(), layout.c_str());
261 if (this->pop ==
nullptr)
262 throw std::logic_error(
"Pool already closed");
264 auto *user_data =
static_cast<detail::pool_data *
>(
265 pmemobj_get_user_data(this->pop));
267 if (user_data->initialized.load())
268 user_data->cleanup();
272 pmemobj_close(this->pop);
283 persist(
const void *addr,
size_t len) noexcept
285 pmemobj_persist(this->pop, addr, len);
293 template <
typename Y>
297 pmemobj_persist(this->pop, &prop,
sizeof(Y));
306 template <
typename Y>
310 pmemobj_persist(this->pop, &ptr,
sizeof(ptr));
320 flush(
const void *addr,
size_t len) noexcept
322 pmemobj_flush(this->pop, addr, len);
330 template <
typename Y>
334 pmemobj_flush(this->pop, &prop,
sizeof(Y));
342 template <
typename Y>
346 pmemobj_flush(this->pop, &ptr,
sizeof(ptr));
355 pmemobj_drain(this->pop);
371 return pmemobj_memcpy_persist(this->pop, dest, src, len);
387 return pmemobj_memset_persist(this->pop, dest, c, len);
403 POBJ_CPP_DEPRECATED PMEMobjpool *
404 get_handle() noexcept
425 pobj_defrag_result result;
426 int ret = pmemobj_defrag(this->pop, (PMEMoid **)ptrv, oidcnt,
431 .with_pmemobj_errormsg();
442 static const int DEFAULT_MODE = S_IWUSR | S_IRUSR;
445 static const int DEFAULT_MODE = S_IWRITE | S_IREAD;
461 template <
typename T>
518 template <
typename M>
522 return ctl_get_detail<M>(pop, name);
536 template <
typename M>
540 return ctl_set_detail(pop, name, arg);
554 template <
typename M>
558 return ctl_exec_detail(pop, name, arg);
572 template <
typename M>
576 return ctl_get_detail<M>(pop, name);
590 template <
typename M>
594 return ctl_set_detail(pop, name, arg);
608 template <
typename M>
612 return ctl_exec_detail(pop, name, arg);
652 open(
const std::string &path,
const std::string &layout)
674 create(
const std::string &path,
const std::string &layout,
675 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
691 check(
const std::string &path,
const std::string &layout)
711 open(
const std::wstring &path,
const std::wstring &layout)
734 create(
const std::wstring &path,
const std::wstring &layout,
735 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
752 check(
const std::wstring &path,
const std::wstring &layout)
769 template <
typename T>
773 return ctl_get_detail<T>(
nullptr, name);
787 template <
typename T>
791 return ctl_set_detail(
nullptr, name, arg);
805 template <
typename T>
809 return ctl_exec_detail(
nullptr, name, arg);
823 template <
typename T>
827 return ctl_get_detail<T>(
nullptr, name);
841 template <
typename T>
845 return ctl_set_detail(
nullptr, name, arg);
859 template <
typename T>
863 return ctl_exec_detail(
nullptr, name, arg);
void * memcpy_persist(void *dest, const void *src, size_t len) noexcept
Performs memcpy and persist operation on a given chunk of memory.
Definition: pool.hpp:369
T ctl_exec(const std::string &name, T arg)
Execute function at global scope.
Definition: pool.hpp:807
void persist(const persistent_ptr< Y > &ptr) noexcept
Performs persist operation on a given persistent pointer.
Definition: pool.hpp:308
static pool_base create(const std::wstring &path, const std::wstring &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:221
M ctl_exec(const std::string &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:556
Custom pool error class.
Definition: pexceptions.hpp:47
pool_base(const pool_base &) noexcept=default
Defaulted copy constructor.
static int check(const std::wstring &path, const std::wstring &layout)
Checks if a given pool is consistent.
Definition: pool.hpp:752
static pool< T > create(const std::string &path, const std::string &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:674
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:283
Persistent memory namespace.
Definition: allocation_flag.hpp:15
M ctl_get(const std::string &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:520
void * memset_persist(void *dest, int c, size_t len) noexcept
Performs memset and persist operation on a given chunk of memory.
Definition: pool.hpp:385
Commonly used functionality.
pool(pool_base &&pb) noexcept
Defaulted move constructor.
Definition: pool.hpp:504
M ctl_get(const std::wstring &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:574
M ctl_set(const std::wstring &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:592
static int check(const std::string &path, const std::string &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:167
pobj_defrag_result defrag(persistent_ptr_base **ptrv, size_t oidcnt)
Starts defragmentation using selected pointers within this pool.
Definition: pool.hpp:423
pool_base(pool_base &&) noexcept=default
Defaulted move constructor.
static int check(const std::wstring &path, const std::wstring &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:247
void drain(void) noexcept
Performs drain operation.
Definition: pool.hpp:353
void persist(const p< Y > &prop) noexcept
Performs persist operation on a given pmem property.
Definition: pool.hpp:295
Resides on pmem class.
Definition: p.hpp:35
static pool_base open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:104
void close()
Closes the pool.
Definition: pool.hpp:259
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:624
pool_base() noexcept
Defaulted constructor.
Definition: pool.hpp:51
void flush(const persistent_ptr< Y > &ptr) noexcept
Performs flush operation on a given persistent object.
Definition: pool.hpp:344
pool() noexcept=default
Defaulted constructor.
T ctl_set(const std::string &name, T arg)
Modify libpmemobj state at global scope.
Definition: pool.hpp:789
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:320
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:398
pool_base(pmemobjpool *cpop) noexcept
Explicit constructor.
Definition: pool.hpp:62
static pool_base create(const std::string &path, const std::string &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:137
M ctl_set(const std::string &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:538
Custom defrag error class.
Definition: pexceptions.hpp:212
Persistent pointer class.
Definition: persistent_ptr.hpp:152
static pool_base open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:191
PMEMobj pool class.
Definition: pool.hpp:462
Resides on pmem property template.
T ctl_get(const std::string &name)
Query libpmemobj state at global scope.
Definition: pool.hpp:771
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:652
M ctl_exec(const std::wstring &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:610
void flush(const p< Y > &prop) noexcept
Performs flush operation on a given pmem property.
Definition: pool.hpp:332
A volatile data stored along with pmemobjpool.
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
Base class for persistent_ptr.
static pool< T > open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:711
static pool< T > create(const std::wstring &path, const std::wstring &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:734
The non-template pool base class.
Definition: pool.hpp:46
static int check(const std::string &path, const std::string &layout)
Checks if a given pool is consistent.
Definition: pool.hpp:691