PMDK C++ bindings
1.7
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_TRANSACTION_HPP
39 #define LIBPMEMOBJ_CPP_TRANSACTION_HPP
47 #include <libpmemobj/tx_base.h>
107 template <
typename... L>
110 if (pmemobj_tx_begin(pop.
handle(),
nullptr,
113 "failed to start transaction");
118 pmemobj_tx_abort(EINVAL);
119 (void)pmemobj_tx_end();
134 if (pmemobj_tx_stage() == TX_STAGE_WORK)
135 pmemobj_tx_abort(ECANCELED);
137 (void)pmemobj_tx_end();
165 #if __cpp_lib_uncaught_exceptions || _MSC_VER >= 1900
204 template <
typename... L>
206 : tx_worker(pop, locks...)
227 if (pmemobj_tx_stage() == TX_STAGE_WORK)
230 else if (pmemobj_tx_stage() == TX_STAGE_ONABORT ||
231 (pmemobj_tx_stage() == TX_STAGE_FINALLY &&
232 pmemobj_tx_errno() != 0))
283 return std::uncaught_exceptions() > this->
count;
327 if (pmemobj_tx_stage() != TX_STAGE_WORK)
330 pmemobj_tx_abort(err);
347 if (pmemobj_tx_stage() != TX_STAGE_WORK)
356 return pmemobj_tx_errno();
359 POBJ_CPP_DEPRECATED
static int
360 get_last_tx_error() noexcept
362 return transaction::error();
396 template <
typename... Locks>
400 if (pmemobj_tx_begin(
pool.handle(),
nullptr, TX_PARAM_NONE) !=
407 pmemobj_tx_abort(err);
408 (void)pmemobj_tx_end();
410 "failed to add a lock to the transaction");
416 (void)pmemobj_tx_end();
420 if (pmemobj_tx_stage() == TX_STAGE_WORK)
421 pmemobj_tx_abort(ECANCELED);
424 (void)pmemobj_tx_end();
428 auto stage = pmemobj_tx_stage();
430 if (stage == TX_STAGE_WORK) {
432 }
else if (stage == TX_STAGE_ONABORT) {
433 (void)pmemobj_tx_end();
435 }
else if (stage == TX_STAGE_NONE) {
437 "transaction ended prematurely");
440 (void)pmemobj_tx_end();
443 template <
typename... Locks>
444 POBJ_CPP_DEPRECATED
static void
445 exec_tx(
pool_base &
pool, std::function<
void()> tx, Locks &... locks)
472 typename std::enable_if<LIBPMEMOBJ_CPP_IS_TRIVIALLY_COPYABLE(T),
473 T>::type * =
nullptr>
477 if (TX_STAGE_WORK != pmemobj_tx_stage())
479 "wrong stage for taking a snapshot.");
481 if (pmemobj_tx_add_range_direct(addr,
sizeof(*addr) * num))
483 "Could not take a snapshot of given memory range.");
499 template <
typename L,
typename... Locks>
504 pmemobj_tx_lock(lock.lock_type(), lock.native_handle());
automatic(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:205
int count
The number of active exceptions.
Definition: transaction.hpp:290
static void commit()
Manually commit a transaction.
Definition: transaction.hpp:345
manual & operator=(manual &&p)=delete
Deleted move assignment operator.
Custom transaction error class.
Definition: pexceptions.hpp:63
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.
Commonly used functionality.
static int add_lock(L &lock, Locks &... locks) noexcept
Recursively add locks to the active transaction.
Definition: transaction.hpp:501
~manual() noexcept
Destructor.
Definition: transaction.hpp:131
static void snapshot(const T *addr, size_t num=1)
Takes a “snapshot” of given elements of type T number (1 by default), located at the given address pt...
Definition: transaction.hpp:475
Resides on pmem class.
Definition: p.hpp:64
manual(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:108
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:398
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:516
automatic & operator=(automatic &&p)=delete
Deleted move assignment operator.
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:398
automatic(const automatic &p)=delete
Deleted copy constructor.
C++ automatic scope transaction class.
Definition: transaction.hpp:185
Internal class for counting active exceptions.
Definition: transaction.hpp:260
bool new_uncaught_exception()
Notifies is a new exception is being handled.
Definition: transaction.hpp:281
uncaught_exception_counter()
Default constructor.
Definition: transaction.hpp:268
PMEMobj pool class.
Definition: pool.hpp:431
manual & operator=(const manual &p)=delete
Deleted assignment operator.
~transaction() noexcept=delete
Default destructor.
~automatic() noexcept(false)
Destructor.
Definition: transaction.hpp:220
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: concurrent_hash_map.hpp:75
manual(const manual &p)=delete
Deleted copy constructor.
C++ transaction handler class.
Definition: transaction.hpp:72
Custom transaction error class.
Definition: pexceptions.hpp:114
The non-template pool base class.
Definition: pool.hpp:67
automatic(const automatic &&p)=delete
Deleted move constructor.
static void abort(int err)
Manually abort the current transaction.
Definition: transaction.hpp:325
C++ manual scope transaction class.
Definition: transaction.hpp:92
manual(const manual &&p)=delete
Deleted move constructor.