38 #ifndef LIBPMEMOBJ_CPP_POOL_HPP 39 #define LIBPMEMOBJ_CPP_POOL_HPP 49 #include <libpmemobj/pool_base.h> 83 explicit pool_base(pmemobjpool *cpop) noexcept : pop(cpop)
128 pmemobjpool *pop = pmemobj_openU(path.c_str(), layout.c_str());
130 pmemobjpool *pop = pmemobj_open(path.c_str(), layout.c_str());
134 .with_pmemobj_errormsg();
156 create(
const std::string &path,
const std::string &layout,
157 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
160 pmemobjpool *pop = pmemobj_createU(path.c_str(), layout.c_str(),
163 pmemobjpool *pop = pmemobj_create(path.c_str(), layout.c_str(),
168 .with_pmemobj_errormsg();
184 check(
const std::string &path,
const std::string &layout) noexcept
187 return pmemobj_checkU(path.c_str(), layout.c_str());
189 return pmemobj_check(path.c_str(), layout.c_str());
208 open(
const std::wstring &path,
const std::wstring &layout)
210 pmemobjpool *pop = pmemobj_openW(path.c_str(), layout.c_str());
213 .with_pmemobj_errormsg();
236 create(
const std::wstring &path,
const std::wstring &layout,
237 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
239 pmemobjpool *pop = pmemobj_createW(path.c_str(), layout.c_str(),
243 .with_pmemobj_errormsg();
260 check(
const std::wstring &path,
const std::wstring &layout) noexcept
262 return pmemobj_checkW(path.c_str(), layout.c_str());
274 if (this->pop ==
nullptr)
275 throw std::logic_error(
"Pool already closed");
277 pmemobj_close(this->pop);
288 persist(
const void *addr,
size_t len) noexcept
290 pmemobj_persist(this->pop, addr, len);
298 template <
typename Y>
302 pmemobj_persist(this->pop, &prop,
sizeof(Y));
311 template <
typename Y>
315 pmemobj_persist(this->pop, &ptr,
sizeof(ptr));
325 flush(
const void *addr,
size_t len) noexcept
327 pmemobj_flush(this->pop, addr, len);
335 template <
typename Y>
339 pmemobj_flush(this->pop, &prop,
sizeof(Y));
347 template <
typename Y>
351 pmemobj_flush(this->pop, &ptr,
sizeof(ptr));
360 pmemobj_drain(this->pop);
376 return pmemobj_memcpy_persist(this->pop, dest, src, len);
392 return pmemobj_memset_persist(this->pop, dest, c, len);
408 POBJ_CPP_DEPRECATED PMEMobjpool *
409 get_handle() noexcept
420 static const int DEFAULT_MODE = S_IWUSR | S_IRUSR;
423 static const int DEFAULT_MODE = S_IWRITE | S_IREAD;
435 template <
typename T>
436 class pool :
public pool_base {
441 pool() noexcept = default;
446 pool(const
pool &) noexcept = default;
456 pool &operator=(const
pool &) noexcept = default;
461 pool &operator=(
pool &&) noexcept = default;
466 ~
pool() noexcept = default;
492 template <
typename M>
496 return ctl_get_detail<M>(pop, name);
510 template <
typename M>
514 return ctl_set_detail(pop, name, arg);
528 template <
typename M>
532 return ctl_exec_detail(pop, name, arg);
546 template <
typename M>
550 return ctl_get_detail<M>(pop, name);
564 template <
typename M>
568 return ctl_set_detail(pop, name, arg);
582 template <
typename M>
586 return ctl_exec_detail(pop, name, arg);
624 open(
const std::string &path,
const std::string &layout)
646 create(
const std::string &path,
const std::string &layout,
647 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
663 check(
const std::string &path,
const std::string &layout)
683 open(
const std::wstring &path,
const std::wstring &layout)
706 create(
const std::wstring &path,
const std::wstring &layout,
707 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode = DEFAULT_MODE)
724 check(
const std::wstring &path,
const std::wstring &layout)
741 template <
typename T>
745 return ctl_get_detail<T>(
nullptr, name);
759 template <
typename T>
763 return ctl_set_detail(
nullptr, name, arg);
777 template <
typename T>
781 return ctl_exec_detail(
nullptr, name, arg);
795 template <
typename T>
799 return ctl_get_detail<T>(
nullptr, name);
813 template <
typename T>
817 return ctl_set_detail(
nullptr, name, arg);
831 template <
typename T>
835 return ctl_exec_detail(
nullptr, name, arg);
M ctl_exec(const std::string &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:530
pool() noexcept=default
Defaulted constructor.
static int check(const std::string &path, const std::string &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:184
T ctl_get(const std::string &name)
Query libpmemobj state at global scope.
Definition: pool.hpp:743
void persist(const persistent_ptr< Y > &ptr) noexcept
Performs persist operation on a given persistent pointer.
Definition: pool.hpp:313
Persistent pointer class.
Definition: common.hpp:125
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:596
The non-template pool base class.
Definition: pool.hpp:67
pool(pool_base &&pb) noexcept
Defaulted move constructor.
Definition: pool.hpp:478
void flush(const p< Y > &prop) noexcept
Performs flush operation on a given pmem property.
Definition: pool.hpp:337
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:374
Custom pool error class.
Definition: pexceptions.hpp:72
static pool_base open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:208
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: concurrent_hash_map.hpp:65
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:624
Resides on pmem property template.
PMEMobj pool class.
Definition: persistent_ptr.hpp:59
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:403
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:156
M ctl_get(const std::string &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:494
Commonly used functionality.
static pool_base open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:125
T ctl_exec(const std::string &name, T arg)
Execute function at global scope.
Definition: pool.hpp:779
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:288
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:390
M ctl_set(const std::wstring &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:566
static int check(const std::wstring &path, const std::wstring &layout)
Checks if a given pool is consistent.
Definition: pool.hpp:724
M ctl_set(const std::string &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:512
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:646
M ctl_get(const std::wstring &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:548
void flush(const persistent_ptr< Y > &ptr) noexcept
Performs flush operation on a given persistent object.
Definition: pool.hpp:349
static int check(const std::wstring &path, const std::wstring &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:260
void persist(const p< Y > &prop) noexcept
Performs persist operation on a given pmem property.
Definition: pool.hpp:300
pool_base() noexcept
Defaulted constructor.
Definition: pool.hpp:72
pool_base(pmemobjpool *cpop) noexcept
Explicit constructor.
Definition: pool.hpp:83
T ctl_set(const std::string &name, T arg)
Modify libpmemobj state at global scope.
Definition: pool.hpp:761
static int check(const std::string &path, const std::string &layout)
Checks if a given pool is consistent.
Definition: pool.hpp:663
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:236
Resides on pmem class.
Definition: p.hpp:64
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:43
void drain(void) noexcept
Performs drain operation.
Definition: pool.hpp:358
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:325
static pool< T > open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:683
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:706
M ctl_exec(const std::wstring &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:584
void close()
Closes the pool.
Definition: pool.hpp:272