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>
206 if (pmemobj_tx_begin(pop.get_handle(), NULL,
209 "failed to start transaction");
214 pmemobj_tx_abort(EINVAL);
230 if (pmemobj_tx_stage() != TX_STAGE_WORK) {
231 (
void)pmemobj_tx_end();
237 pmemobj_tx_abort(ECANCELED);
242 (
void)pmemobj_tx_end();
278 :
count(std::uncaught_exceptions())
292 return std::uncaught_exceptions() > this->
count;
334 if (pmemobj_tx_stage() != TX_STAGE_WORK)
338 pmemobj_tx_abort(err);
355 if (pmemobj_tx_stage() != TX_STAGE_WORK)
363 get_last_tx_error() noexcept
365 return pmemobj_tx_errno();
399 template <
typename... Locks>
401 exec_tx(pool_base &pool, std::function<
void()> tx, Locks &... locks)
403 if (pmemobj_tx_begin(pool.get_handle(), NULL, TX_PARAM_NONE) !=
410 pmemobj_tx_abort(err);
411 (
void)pmemobj_tx_end();
419 (
void)pmemobj_tx_end();
423 if (pmemobj_tx_stage() == TX_STAGE_WORK)
424 pmemobj_tx_abort(ECANCELED);
427 (
void)pmemobj_tx_end();
431 auto stage = pmemobj_tx_stage();
433 if (stage == TX_STAGE_WORK) {
435 }
else if (stage == TX_STAGE_ONABORT) {
436 (
void)pmemobj_tx_end();
438 }
else if (stage == TX_STAGE_NONE) {
443 (
void)pmemobj_tx_end();
459 template <
typename L,
typename... Locks>
464 pmemobj_tx_lock(lock.lock_type(), lock.native_handle());
static int add_lock(L &lock, Locks &...locks) noexcept
Recursively add locks to the active transaction.
Definition: transaction.hpp:461
C++ automatic scope transaction class.
Definition: transaction.hpp:184
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:476
static void abort(int err)
Manually abort the current transaction.
Definition: transaction.hpp:332
Internal class for counting active exceptions.
Definition: transaction.hpp:269
manual & operator=(const manual &p)=delete
Deleted assignment operator.
The non-template pool base class.
Definition: pool.hpp:64
bool new_uncaught_exception()
Notifies is a new exception is being handled.
Definition: transaction.hpp:290
Custom transaction error class.
Definition: pexceptions.hpp:114
static void
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:402
manual(obj::pool_base &pop, L &...locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:107
Custom transaction error class.
Definition: pexceptions.hpp:63
~transaction() noexcept=delete
Default destructor.
~automatic() noexcept
Destructor.
Definition: transaction.hpp:227
C++ manual scope transaction class.
Definition: transaction.hpp:91
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.
int count
The number of active exceptions.
Definition: transaction.hpp:299
Resides on pmem class.
Definition: p.hpp:64
automatic(obj::pool_base &pop, L &...locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:204
~manual() noexcept
Destructor.
Definition: transaction.hpp:130
C++ transaction handler class.
Definition: transaction.hpp:71
uncaught_exception_counter()
Default constructor.
Definition: transaction.hpp:277
static void commit()
Manually commit a transaction.
Definition: transaction.hpp:353