PMDK C++ bindings
1.12-git53.g67ba2be4
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;
464 template <
typename T>
521 template <
typename M>
525 return ctl_get_detail<M>(pop, name);
539 template <
typename M>
543 return ctl_set_detail(pop, name, arg);
557 template <
typename M>
561 return ctl_exec_detail(pop, name, arg);
575 template <
typename M>
579 return ctl_get_detail<M>(pop, name);
593 template <
typename M>
597 return ctl_set_detail(pop, name, arg);
611 template <
typename M>
615 return ctl_exec_detail(pop, name, arg);
655 open(
const std::string &path,
const std::string &layout)
677 create(
const std::string &path,
const std::string &layout,
678 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
694 check(
const std::string &path,
const std::string &layout)
714 open(
const std::wstring &path,
const std::wstring &layout)
737 create(
const std::wstring &path,
const std::wstring &layout,
738 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
755 check(
const std::wstring &path,
const std::wstring &layout)
772 template <
typename T>
776 return ctl_get_detail<T>(
nullptr, name);
790 template <
typename T>
794 return ctl_set_detail(
nullptr, name, arg);
808 template <
typename T>
812 return ctl_exec_detail(
nullptr, name, arg);
826 template <
typename T>
830 return ctl_get_detail<T>(
nullptr, name);
844 template <
typename T>
848 return ctl_set_detail(
nullptr, name, arg);
862 template <
typename T>
866 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:810
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:559
Custom pool error class.
Definition: pexceptions.hpp:45
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:755
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:677
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:523
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:507
M ctl_get(const std::wstring &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:577
M ctl_set(const std::wstring &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:595
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:627
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:792
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:541
Custom defrag error class.
Definition: pexceptions.hpp:207
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:465
Resides on pmem property template.
T ctl_get(const std::string &name)
Query libpmemobj state at global scope.
Definition: pool.hpp:774
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:655
M ctl_exec(const std::wstring &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:613
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:714
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:737
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:694