9 #ifndef LIBPMEMOBJ_CPP_POOL_HPP
10 #define LIBPMEMOBJ_CPP_POOL_HPP
19 #include <unordered_map>
28 #include <libpmemobj/atomic_base.h>
29 #include <libpmemobj/pool_base.h>
66 explicit pool_base(pmemobjpool *cpop) noexcept : pop(cpop)
108 open(const std::
string &path, const std::
string &layout)
111 pmemobjpool *pop = pmemobj_openU(path.c_str(), layout.c_str());
113 pmemobjpool *pop = pmemobj_open(path.c_str(), layout.c_str());
115 check_pool(pop,
"opening");
117 pmemobj_set_user_data(pop,
new detail::pool_data);
139 create(
const std::string &path,
const std::string &layout,
140 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
143 pmemobjpool *pop = pmemobj_createU(path.c_str(), layout.c_str(),
146 pmemobjpool *pop = pmemobj_create(path.c_str(), layout.c_str(),
149 check_pool(pop,
"creating");
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());
194 check_pool(pop,
"opening");
196 pmemobj_set_user_data(pop,
new detail::pool_data);
219 create(
const std::wstring &path,
const std::wstring &layout,
220 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
222 pmemobjpool *pop = pmemobj_createW(path.c_str(), layout.c_str(),
224 check_pool(pop,
"creating");
226 pmemobj_set_user_data(pop,
new detail::pool_data);
243 check(
const std::wstring &path,
const std::wstring &layout) noexcept
245 return pmemobj_checkW(path.c_str(), layout.c_str());
257 if (this->pop ==
nullptr)
258 throw std::logic_error(
"Pool already closed");
260 auto *user_data =
static_cast<detail::pool_data *
>(
261 pmemobj_get_user_data(this->pop));
263 if (user_data->initialized.load())
264 user_data->cleanup();
268 pmemobj_close(this->pop);
279 persist(
const void *addr,
size_t len) noexcept
281 pmemobj_persist(this->pop, addr, len);
289 template <
typename Y>
293 pmemobj_persist(this->pop, &prop,
sizeof(Y));
302 template <
typename Y>
306 pmemobj_persist(this->pop, &ptr,
sizeof(ptr));
316 flush(
const void *addr,
size_t len) noexcept
318 pmemobj_flush(this->pop, addr, len);
326 template <
typename Y>
330 pmemobj_flush(this->pop, &prop,
sizeof(Y));
338 template <
typename Y>
342 pmemobj_flush(this->pop, &ptr,
sizeof(ptr));
351 pmemobj_drain(this->pop);
367 return pmemobj_memcpy_persist(this->pop, dest, src, len);
383 return pmemobj_memset_persist(this->pop, dest, c, len);
399 POBJ_CPP_DEPRECATED PMEMobjpool *
400 get_handle() noexcept
421 pobj_defrag_result result;
422 int ret = pmemobj_defrag(this->pop, (PMEMoid **)ptrv, oidcnt,
427 .with_pmemobj_errormsg();
434 check_pool(pmemobjpool *pop, std::string mode)
436 if (pop ==
nullptr) {
437 if (errno == EINVAL || errno == EFBIG ||
438 errno == ENOENT || errno == EEXIST) {
440 "Failed " + mode +
" pool")
441 .with_pmemobj_errormsg();
445 .with_pmemobj_errormsg();
481 template <
typename T>
538 template <
typename M>
542 return ctl_get_detail<M>(pop, name);
556 template <
typename M>
560 return ctl_set_detail(pop, name, arg);
574 template <
typename M>
578 return ctl_exec_detail(pop, name, arg);
592 template <
typename M>
596 return ctl_get_detail<M>(pop, name);
610 template <
typename M>
614 return ctl_set_detail(pop, name, arg);
628 template <
typename M>
632 return ctl_exec_detail(pop, name, arg);
672 open(
const std::string &path,
const std::string &layout)
694 create(
const std::string &path,
const std::string &layout,
695 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
711 check(
const std::string &path,
const std::string &layout)
731 open(
const std::wstring &path,
const std::wstring &layout)
754 create(
const std::wstring &path,
const std::wstring &layout,
755 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
772 check(
const std::wstring &path,
const std::wstring &layout)
789 template <
typename T>
793 return ctl_get_detail<T>(
nullptr, name);
807 template <
typename T>
811 return ctl_set_detail(
nullptr, name, arg);
825 template <
typename T>
829 return ctl_exec_detail(
nullptr, name, arg);
843 template <
typename T>
847 return ctl_get_detail<T>(
nullptr, name);
861 template <
typename T>
865 return ctl_set_detail(
nullptr, name, arg);
879 template <
typename T>
883 return ctl_exec_detail(
nullptr, name, arg);
Custom defrag error class.
Definition: pexceptions.hpp:225
Resides on pmem class.
Definition: p.hpp:35
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
Persistent pointer class.
Definition: persistent_ptr.hpp:152
The non-template pool base class.
Definition: pool.hpp:50
static pool_base open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:108
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:394
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:316
pobj_defrag_result defrag(persistent_ptr_base **ptrv, size_t oidcnt)
Starts defragmentation using selected pointers within this pool.
Definition: pool.hpp:419
void flush(const p< Y > &prop) noexcept
Performs flush operation on a given pmem property.
Definition: pool.hpp:328
static int check(const std::wstring &path, const std::wstring &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:243
void persist(const persistent_ptr< Y > &ptr) noexcept
Performs persist operation on a given persistent pointer.
Definition: pool.hpp:304
pool_base(pool_base &&) noexcept=default
Defaulted move constructor.
void close()
Closes the pool.
Definition: pool.hpp:255
void persist(const p< Y > &prop) noexcept
Performs persist operation on a given pmem property.
Definition: pool.hpp:291
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:279
pool_base(pmemobjpool *cpop) noexcept
Explicit constructor.
Definition: pool.hpp:66
void flush(const persistent_ptr< Y > &ptr) noexcept
Performs flush operation on a given persistent object.
Definition: pool.hpp:340
static const int DEFAULT_MODE
Default create mode.
Definition: pool.hpp:462
pool_base() noexcept
Defaulted constructor.
Definition: pool.hpp:55
static pool_base open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:191
pool_base(const pool_base &) noexcept=default
Defaulted copy constructor.
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:139
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:381
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:219
void drain(void) noexcept
Performs drain operation.
Definition: pool.hpp:349
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:365
static int check(const std::string &path, const std::string &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:167
PMEMobj pool class.
Definition: pool.hpp:482
static pool< T > open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:731
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:672
static int check(const std::string &path, const std::string &layout)
Checks if a given pool is consistent.
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:754
M ctl_set(const std::wstring &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:612
M ctl_set(const std::string &name, M arg)
Modify libpmemobj state at pool scope.
Definition: pool.hpp:558
pool(pool_base &&pb) noexcept
Defaulted move constructor.
Definition: pool.hpp:524
M ctl_exec(const std::string &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:576
M ctl_get(const std::string &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:540
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:644
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:694
static int check(const std::wstring &path, const std::wstring &layout)
Checks if a given pool is consistent.
Definition: pool.hpp:772
M ctl_get(const std::wstring &name)
Query libpmemobj state at pool scope.
Definition: pool.hpp:594
pool() noexcept=default
Defaulted constructor.
M ctl_exec(const std::wstring &name, M arg)
Execute function at pool scope.
Definition: pool.hpp:630
Custom pool error class.
Definition: pexceptions.hpp:45
Custom pool error class.
Definition: pexceptions.hpp:63
Commonly used functionality.
T ctl_set(const std::string &name, T arg)
Modify libpmemobj state at global scope.
Definition: pool.hpp:809
T ctl_get(const std::string &name)
Query libpmemobj state at global scope.
Definition: pool.hpp:791
T ctl_exec(const std::string &name, T arg)
Execute function at global scope.
Definition: pool.hpp:827
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Resides on pmem property template.
Base class for persistent_ptr.
A volatile data stored along with pmemobjpool.