38#ifndef LIBPMEMOBJ_TRANSACTION_HPP
39#define LIBPMEMOBJ_TRANSACTION_HPP
46#include "libpmemobj/tx_base.h"
106 template <
typename... L>
109 if (pmemobj_tx_begin(pop.get_handle(), NULL,
112 "failed to start transaction");
117 pmemobj_tx_abort(EINVAL);
133 if (pmemobj_tx_stage() == TX_STAGE_WORK)
134 pmemobj_tx_abort(ECANCELED);
136 (void)pmemobj_tx_end();
164#if __cpp_lib_uncaught_exceptions || _MSC_VER >= 1900
203 template <
typename... L>
205 : tx_worker(pop, locks...)
226 if (pmemobj_tx_stage() == TX_STAGE_WORK)
229 else if (pmemobj_tx_stage() == TX_STAGE_ONABORT ||
230 (pmemobj_tx_stage() == TX_STAGE_FINALLY &&
231 pmemobj_tx_errno() != 0))
268 :
count(std::uncaught_exceptions())
282 return std::uncaught_exceptions() > this->
count;
326 if (pmemobj_tx_stage() != TX_STAGE_WORK)
330 pmemobj_tx_abort(err);
347 if (pmemobj_tx_stage() != TX_STAGE_WORK)
355 get_last_tx_error() noexcept
357 return pmemobj_tx_errno();
391 template <
typename... Locks>
395 if (pmemobj_tx_begin(
pool.get_handle(), NULL, TX_PARAM_NONE) !=
402 pmemobj_tx_abort(err);
403 (void)pmemobj_tx_end();
411 (void)pmemobj_tx_end();
415 if (pmemobj_tx_stage() == TX_STAGE_WORK)
416 pmemobj_tx_abort(ECANCELED);
419 (void)pmemobj_tx_end();
423 auto stage = pmemobj_tx_stage();
425 if (stage == TX_STAGE_WORK) {
427 }
else if (stage == TX_STAGE_ONABORT) {
428 (void)pmemobj_tx_end();
430 }
else if (stage == TX_STAGE_NONE) {
435 (void)pmemobj_tx_end();
451 template <
typename L,
typename... Locks>
456 pmemobj_tx_lock(lock.lock_type(), lock.native_handle());
Custom transaction error class.
Definition: pexceptions.hpp:114
Resides on pmem class.
Definition: p.hpp:64
The non-template pool base class.
Definition: pool.hpp:65
PMEMobj pool class.
Definition: pool.hpp:423
Internal class for counting active exceptions.
Definition: transaction.hpp:259
bool new_uncaught_exception()
Notifies is a new exception is being handled.
Definition: transaction.hpp:280
uncaught_exception_counter()
Default constructor.
Definition: transaction.hpp:267
int count
The number of active exceptions.
Definition: transaction.hpp:289
C++ automatic scope transaction class.
Definition: transaction.hpp:184
automatic(const automatic &&p)=delete
Deleted move constructor.
~automatic() noexcept(false)
Destructor.
Definition: transaction.hpp:219
automatic(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:204
automatic & operator=(automatic &&p)=delete
Deleted move assignment operator.
automatic(const automatic &p)=delete
Deleted copy constructor.
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.
C++ manual scope transaction class.
Definition: transaction.hpp:91
manual & operator=(manual &&p)=delete
Deleted move assignment operator.
manual(const manual &&p)=delete
Deleted move constructor.
~manual() noexcept
Destructor.
Definition: transaction.hpp:130
manual(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:107
manual & operator=(const manual &p)=delete
Deleted assignment operator.
manual(const manual &p)=delete
Deleted copy constructor.
C++ transaction handler class.
Definition: transaction.hpp:71
static void commit()
Manually commit a transaction.
Definition: transaction.hpp:345
static void abort(int err)
Manually abort the current transaction.
Definition: transaction.hpp:324
~transaction() noexcept=delete
Default destructor.
static int add_lock(L &lock, Locks &... locks) noexcept
Recursively add locks to the active transaction.
Definition: transaction.hpp:453
static void exec_tx(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:393
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:468
Custom transaction error class.
Definition: pexceptions.hpp:63