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());
int count
The number of active exceptions.
Definition: transaction.hpp:290
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:516
The non-template pool base class.
Definition: pool.hpp:67
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
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: concurrent_hash_map.hpp:74
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
C++ manual scope transaction class.
Definition: transaction.hpp:92
PMEMobj pool class.
Definition: persistent_ptr.hpp:59
manual & operator=(const manual &p)=delete
Deleted assignment operator.
PMEMobjpool * handle() noexcept
Gets the C style handle to the pool.
Definition: pool.hpp:398
manual(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:108
Commonly used functionality.
static void commit()
Manually commit a transaction.
Definition: transaction.hpp:345
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
static int add_lock(L &lock, Locks &... locks) noexcept
Recursively add locks to the active transaction.
Definition: transaction.hpp:501
bool new_uncaught_exception()
Notifies is a new exception is being handled.
Definition: transaction.hpp:281
automatic(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:205
uncaught_exception_counter()
Default constructor.
Definition: transaction.hpp:268
Resides on pmem class.
Definition: p.hpp:64
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:398
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.