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>
67 explicit pool_base(pmemobjpool *cpop) noexcept : pop(cpop)
109 open(const std::
string &path, const std::
string &layout)
112 pmemobjpool *pop = pmemobj_openU(path.c_str(), layout.c_str());
114 pmemobjpool *pop = pmemobj_open(path.c_str(), layout.c_str());
116 check_pool(pop,
"opening");
118 pmemobj_set_user_data(pop,
new detail::pool_data);
141 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
144 pmemobjpool *pop = pmemobj_createU(path.c_str(), layout.c_str(),
147 pmemobjpool *pop = pmemobj_create(path.c_str(), layout.c_str(),
150 check_pool(pop,
"creating");
152 pmemobj_set_user_data(pop,
new detail::pool_data);
171 return pmemobj_checkU(path.c_str(), layout.c_str());
173 return pmemobj_check(path.c_str(), layout.c_str());
194 pmemobjpool *pop = pmemobj_openW(path.c_str(), layout.c_str());
195 check_pool(pop,
"opening");
197 pmemobj_set_user_data(pop,
new detail::pool_data);
221 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
223 pmemobjpool *pop = pmemobj_createW(path.c_str(), layout.c_str(),
225 check_pool(pop,
"creating");
227 pmemobj_set_user_data(pop,
new detail::pool_data);
246 return pmemobj_checkW(path.c_str(), layout.c_str());
258 if (this->pop ==
nullptr)
259 throw std::logic_error(
"Pool already closed");
261 auto *user_data =
static_cast<detail::pool_data *
>(
262 pmemobj_get_user_data(this->pop));
264 if (user_data->initialized.load())
265 user_data->cleanup();
269 pmemobj_close(this->pop);
280 persist(
const void *addr,
size_t len) noexcept
282 pmemobj_persist(this->pop, addr, len);
290 template <
typename Y>
294 pmemobj_persist(this->pop, &prop,
sizeof(Y));
303 template <
typename Y>
307 pmemobj_persist(this->pop, &ptr,
sizeof(ptr));
317 flush(
const void *addr,
size_t len) noexcept
319 pmemobj_flush(this->pop, addr, len);
327 template <
typename Y>
331 pmemobj_flush(this->pop, &prop,
sizeof(Y));
339 template <
typename Y>
343 pmemobj_flush(this->pop, &ptr,
sizeof(ptr));
352 pmemobj_drain(this->pop);
368 return pmemobj_memcpy_persist(this->pop, dest, src, len);
384 return pmemobj_memset_persist(this->pop, dest, c, len);
400 POBJ_CPP_DEPRECATED PMEMobjpool *
401 get_handle() noexcept
422 pobj_defrag_result result;
423 int ret = pmemobj_defrag(this->pop, (PMEMoid **)ptrv, oidcnt,
427 throw detail::exception_with_errormsg<defrag_error>(
428 result,
"Defragmentation failed");
436 if (pop ==
nullptr) {
438 if (errno == EINVAL || errno == EFBIG ||
439 errno == ENOENT || errno == EEXIST) {
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);
695 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
755 std::size_t size = PMEMOBJ_MIN_POOL, mode_t mode =
DEFAULT_MODE)
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);
Resides on pmem class.
Definition: p.hpp:36
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
Persistent pointer class.
Definition: persistent_ptr.hpp:153
The non-template pool base class.
Definition: pool.hpp:51
static pool_base open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:109
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:395
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:317
pobj_defrag_result defrag(persistent_ptr_base **ptrv, size_t oidcnt)
Starts defragmentation using selected pointers within this pool.
Definition: pool.hpp:420
void flush(const p< Y > &prop) noexcept
Performs flush operation on a given pmem property.
Definition: pool.hpp:329
static int check(const std::wstring &path, const std::wstring &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:244
void persist(const persistent_ptr< Y > &ptr) noexcept
Performs persist operation on a given persistent pointer.
Definition: pool.hpp:305
pool_base(pool_base &&) noexcept=default
Defaulted move constructor.
void close()
Closes the pool.
Definition: pool.hpp:256
void persist(const p< Y > &prop) noexcept
Performs persist operation on a given pmem property.
Definition: pool.hpp:292
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:280
pool_base(pmemobjpool *cpop) noexcept
Explicit constructor.
Definition: pool.hpp:67
void flush(const persistent_ptr< Y > &ptr) noexcept
Performs flush operation on a given persistent object.
Definition: pool.hpp:341
static const int DEFAULT_MODE
Default create mode.
Definition: pool.hpp:461
pool_base() noexcept
Defaulted constructor.
Definition: pool.hpp:56
static pool_base open(const std::wstring &path, const std::wstring &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:192
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:140
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:382
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:220
void drain(void) noexcept
Performs drain operation.
Definition: pool.hpp:350
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:366
static int check(const std::string &path, const std::string &layout) noexcept
Checks if a given pool is consistent.
Definition: pool.hpp:168
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:84
Custom pool error class.
Definition: pexceptions.hpp:97
Commonly used functionality.
basic_string< char > string
The most typical string usage - the char specialization.
Definition: string.hpp:24
basic_string< wchar_t > wstring
The wide char specialization.
Definition: string.hpp:30
ExcT exception_with_errormsg(Args &&... args)
Generic error message decorator for pmemobj-based exceptions.
Definition: pexceptions.hpp:69
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.