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);
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))
269 :
count(std::uncaught_exceptions())
283 return std::uncaught_exceptions() > this->
count;
327 if (pmemobj_tx_stage() != TX_STAGE_WORK)
331 pmemobj_tx_abort(err);
348 if (pmemobj_tx_stage() != TX_STAGE_WORK)
358 return pmemobj_tx_errno();
361 POBJ_CPP_DEPRECATED
static int
362 get_last_tx_error() noexcept
364 return transaction::error();
398 template <
typename... Locks>
400 run(pool_base &pool, std::function<
void()> tx, Locks &... locks)
402 if (pmemobj_tx_begin(pool.handle(),
nullptr, TX_PARAM_NONE) !=
409 pmemobj_tx_abort(err);
410 (
void)pmemobj_tx_end();
418 (
void)pmemobj_tx_end();
422 if (pmemobj_tx_stage() == TX_STAGE_WORK)
423 pmemobj_tx_abort(ECANCELED);
426 (
void)pmemobj_tx_end();
430 auto stage = pmemobj_tx_stage();
432 if (stage == TX_STAGE_WORK) {
434 }
else if (stage == TX_STAGE_ONABORT) {
435 (
void)pmemobj_tx_end();
437 }
else if (stage == TX_STAGE_NONE) {
442 (
void)pmemobj_tx_end();
445 template <
typename... Locks>
446 POBJ_CPP_DEPRECATED
static void
447 exec_tx(
pool_base &pool, std::function<
void()> tx, Locks &... locks)
449 transaction::run(pool, tx, locks...);
465 template <
typename L,
typename... Locks>
470 pmemobj_tx_lock(lock.lock_type(), lock.native_handle());
int count
The number of active exceptions.
Definition: transaction.hpp:290
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:482
The non-template pool base class.
Definition: pool.hpp:66
static int add_lock(L &lock, Locks &...locks) noexcept
Recursively add locks to the active transaction.
Definition: transaction.hpp:467
Internal class for counting active exceptions.
Definition: transaction.hpp:260
~manual() noexcept
Destructor.
Definition: transaction.hpp:131
~automatic() noexcept(false)
Destructor.
Definition: transaction.hpp:220
C++ transaction handler class.
Definition: transaction.hpp:72
Custom transaction error class.
Definition: pexceptions.hpp:114
C++ manual scope transaction class.
Definition: transaction.hpp:92
manual & operator=(const manual &p)=delete
Deleted assignment operator.
Commonly used functionality.
automatic(obj::pool_base &pop, L &...locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:205
static void commit()
Manually commit a transaction.
Definition: transaction.hpp:346
static void abort(int err)
Manually abort the current transaction.
Definition: transaction.hpp:325
~transaction() noexcept=delete
Default destructor.
C++ automatic scope transaction class.
Definition: transaction.hpp:185
Custom transaction error class.
Definition: pexceptions.hpp:63
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
Resides on pmem class.
Definition: p.hpp:64
static void
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:401
manual(obj::pool_base &pop, L &...locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:108
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.