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_POOL_HPP
39 #define LIBPMEMOBJ_CPP_POOL_HPP
47 #include <unordered_map>
56 #include <libpmemobj/atomic_base.h>
57 #include <libpmemobj/pool_base.h>
91 explicit pool_base(pmemobjpool *cpop) noexcept : pop(cpop)
133 open(const std::
string &path, const std::
string &layout)
136 pmemobjpool *pop = pmemobj_openU(path.c_str(), layout.c_str());
138 pmemobjpool *pop = pmemobj_open(path.c_str(), layout.c_str());
142 .with_pmemobj_errormsg();
144 pmemobj_set_user_data(pop,
new detail::pool_data);
166 create(
const std::string &path,
const std::string &layout,
167 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
170 pmemobjpool *pop = pmemobj_createU(path.c_str(), layout.c_str(),
173 pmemobjpool *pop = pmemobj_create(path.c_str(), layout.c_str(),
178 .with_pmemobj_errormsg();
180 pmemobj_set_user_data(pop,
new detail::pool_data);
196 check(
const std::string &path,
const std::string &layout) noexcept
199 return pmemobj_checkU(path.c_str(), layout.c_str());
201 return pmemobj_check(path.c_str(), layout.c_str());
220 open(
const std::wstring &path,
const std::wstring &layout)
222 pmemobjpool *pop = pmemobj_openW(path.c_str(), layout.c_str());
225 .with_pmemobj_errormsg();
227 pmemobj_set_user_data(pop,
new detail::pool_data);
250 create(
const std::wstring &path,
const std::wstring &layout,
251 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
253 pmemobjpool *pop = pmemobj_createW(path.c_str(), layout.c_str(),
257 .with_pmemobj_errormsg();
259 pmemobj_set_user_data(pop,
new detail::pool_data);
276 check(
const std::wstring &path,
const std::wstring &layout) noexcept
278 return pmemobj_checkW(path.c_str(), layout.c_str());
290 if (this->pop ==
nullptr)
291 throw std::logic_error(
"Pool already closed");
293 auto *user_data =
static_cast<detail::pool_data *
>(
294 pmemobj_get_user_data(this->pop));
296 if (user_data->initialized.load())
297 user_data->cleanup();
301 pmemobj_close(this->pop);
312 persist(
const void *addr,
size_t len) noexcept
314 pmemobj_persist(this->pop, addr, len);
322 template <
typename Y>
326 pmemobj_persist(this->pop, &prop,
sizeof(Y));
335 template <
typename Y>
339 pmemobj_persist(this->pop, &ptr,
sizeof(ptr));
349 flush(
const void *addr,
size_t len) noexcept
351 pmemobj_flush(this->pop, addr, len);
359 template <
typename Y>
363 pmemobj_flush(this->pop, &prop,
sizeof(Y));
371 template <
typename Y>
375 pmemobj_flush(this->pop, &ptr,
sizeof(ptr));
384 pmemobj_drain(this->pop);
400 return pmemobj_memcpy_persist(this->pop, dest, src, len);
416 return pmemobj_memset_persist(this->pop, dest, c, len);
432 POBJ_CPP_DEPRECATED PMEMobjpool *
433 get_handle() noexcept
454 pobj_defrag_result result;
455 int ret = pmemobj_defrag(this->pop, (PMEMoid **)ptrv, oidcnt,
460 .with_pmemobj_errormsg();
471 static const int DEFAULT_MODE = S_IWUSR | S_IRUSR;
474 static const int DEFAULT_MODE = S_IWRITE | S_IREAD;
490 template <
typename T>
547 template <
typename M>
551 return ctl_get_detail<M>(pop, name);
565 template <
typename M>
569 return ctl_set_detail(pop, name, arg);
583 template <
typename M>
587 return ctl_exec_detail(pop, name, arg);
601 template <
typename M>
605 return ctl_get_detail<M>(pop, name);
619 template <
typename M>
623 return ctl_set_detail(pop, name, arg);
637 template <
typename M>
641 return ctl_exec_detail(pop, name, arg);
679 open(
const std::string &path,
const std::string &layout)
701 create(
const std::string &path,
const std::string &layout,
702 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
718 check(
const std::string &path,
const std::string &layout)
738 open(
const std::wstring &path,
const std::wstring &layout)
761 create(
const std::wstring &path,
const std::wstring &layout,
762 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
779 check(
const std::wstring &path,
const std::wstring &layout)
796 template <
typename T>
800 return ctl_get_detail<T>(
nullptr, name);
814 template <
typename T>
818 return ctl_set_detail(
nullptr, name, arg);
832 template <
typename T>
836 return ctl_exec_detail(
nullptr, name, arg);
850 template <
typename T>
854 return ctl_get_detail<T>(
nullptr, name);
868 template <
typename T>
872 return ctl_set_detail(
nullptr, name, arg);
886 template <
typename T>
890 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:398
T ctl_exec(const std::string &name, T arg)
Execute function at global scope.
Definition: pool.hpp:834
void persist(const persistent_ptr< Y > &ptr) noexcept
Performs persist operation on a given persistent pointer.
Definition: pool.hpp:337
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:250
M ctl_exec(const std::string &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:585
Custom pool error class.
Definition: pexceptions.hpp:74
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:779
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:701
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:312
Persistent memory namespace.
Definition: allocation_flag.hpp:44
M ctl_get(const std::string &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:549
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:414
Commonly used functionality.
pool(pool_base &&pb) noexcept
Defaulted move constructor.
Definition: pool.hpp:533
M ctl_get(const std::wstring &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:603
M ctl_set(const std::wstring &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:621
static int check(const std::string &path, const std::string &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:196
pobj_defrag_result defrag(persistent_ptr_base **ptrv, size_t oidcnt)
Starts defragmentation using selected pointers within this pool.
Definition: pool.hpp:452
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:276
void drain(void) noexcept
Performs drain operation.
Definition: pool.hpp:382
void persist(const p< Y > &prop) noexcept
Performs persist operation on a given pmem property.
Definition: pool.hpp:324
Resides on pmem class.
Definition: p.hpp:64
static pool_base open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:133
void close()
Closes the pool.
Definition: pool.hpp:288
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:651
pool_base() noexcept
Defaulted constructor.
Definition: pool.hpp:80
void flush(const persistent_ptr< Y > &ptr) noexcept
Performs flush operation on a given persistent object.
Definition: pool.hpp:373
pool() noexcept=default
Defaulted constructor.
T ctl_set(const std::string &name, T arg)
Modify libpmemobj state at global scope.
Definition: pool.hpp:816
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:349
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:427
pool_base(pmemobjpool *cpop) noexcept
Explicit constructor.
Definition: pool.hpp:91
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:166
M ctl_set(const std::string &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:567
Custom defrag error class.
Definition: pexceptions.hpp:236
Persistent pointer class.
Definition: persistent_ptr.hpp:212
static pool_base open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:220
PMEMobj pool class.
Definition: pool.hpp:491
Resides on pmem property template.
T ctl_get(const std::string &name)
Query libpmemobj state at global scope.
Definition: pool.hpp:798
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:679
M ctl_exec(const std::wstring &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:639
void flush(const p< Y > &prop) noexcept
Performs flush operation on a given pmem property.
Definition: pool.hpp:361
A volatile data stored along with pmemobjpool.
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:71
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:738
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:761
The non-template pool base class.
Definition: pool.hpp:75
static int check(const std::string &path, const std::string &layout)
Checks if a given pool is consistent.
Definition: pool.hpp:718