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")
114 .with_pmemobj_errormsg();
119 pmemobj_tx_abort(EINVAL);
120 (void)pmemobj_tx_end();
122 "failed to add lock")
123 .with_pmemobj_errormsg();
137 if (pmemobj_tx_stage() == TX_STAGE_WORK)
138 pmemobj_tx_abort(ECANCELED);
140 (void)pmemobj_tx_end();
168 #if __cpp_lib_uncaught_exceptions || _MSC_VER >= 1900 207 template <
typename... L>
209 : tx_worker(pop, locks...)
230 if (pmemobj_tx_stage() == TX_STAGE_WORK)
233 else if (pmemobj_tx_stage() == TX_STAGE_ONABORT ||
234 (pmemobj_tx_stage() == TX_STAGE_FINALLY &&
235 pmemobj_tx_errno() != 0))
237 "Transaction aborted");
287 return std::uncaught_exceptions() > this->
count;
331 if (pmemobj_tx_stage() != TX_STAGE_WORK)
334 pmemobj_tx_abort(err);
336 std::to_string(err));
352 if (pmemobj_tx_stage() != TX_STAGE_WORK)
361 return pmemobj_tx_errno();
364 POBJ_CPP_DEPRECATED
static int 365 get_last_tx_error() noexcept
367 return transaction::error();
401 template <
typename... Locks>
405 if (pmemobj_tx_begin(
pool.
handle(),
nullptr, TX_PARAM_NONE) !=
408 "failed to start transaction")
409 .with_pmemobj_errormsg();
414 pmemobj_tx_abort(err);
415 (void)pmemobj_tx_end();
417 "failed to add a lock to the transaction")
418 .with_pmemobj_errormsg();
424 (void)pmemobj_tx_end();
428 if (pmemobj_tx_stage() == TX_STAGE_WORK)
429 pmemobj_tx_abort(ECANCELED);
432 (void)pmemobj_tx_end();
436 auto stage = pmemobj_tx_stage();
438 if (stage == TX_STAGE_WORK) {
440 }
else if (stage == TX_STAGE_ONABORT) {
441 (void)pmemobj_tx_end();
443 }
else if (stage == TX_STAGE_NONE) {
445 "transaction ended prematurely");
448 (void)pmemobj_tx_end();
451 template <
typename... Locks>
452 POBJ_CPP_DEPRECATED
static void 453 exec_tx(
pool_base &
pool, std::function<
void()> tx, Locks &... locks)
480 typename std::enable_if<LIBPMEMOBJ_CPP_IS_TRIVIALLY_COPYABLE(T),
481 T>::type * =
nullptr>
485 if (TX_STAGE_WORK != pmemobj_tx_stage())
487 "wrong stage for taking a snapshot.");
489 if (pmemobj_tx_add_range_direct(addr,
sizeof(*addr) * num)) {
492 "Could not take a snapshot of given memory range.")
493 .with_pmemobj_errormsg();
496 "Could not take a snapshot of given memory range.")
497 .with_pmemobj_errormsg();
514 template <
typename L,
typename... Locks>
519 pmemobj_tx_lock(lock.lock_type(), lock.native_handle());
int count
The number of active exceptions.
Definition: transaction.hpp:294
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:531
The non-template pool base class.
Definition: pool.hpp:67
Internal class for counting active exceptions.
Definition: transaction.hpp:264
~manual() noexcept
Destructor.
Definition: transaction.hpp:134
~automatic() noexcept(false)
Destructor.
Definition: transaction.hpp:223
C++ transaction handler class.
Definition: transaction.hpp:72
Custom transaction error class.
Definition: pexceptions.hpp:195
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: concurrent_hash_map.hpp:65
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:483
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:403
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:350
static void abort(int err)
Manually abort the current transaction.
Definition: transaction.hpp:329
~transaction() noexcept=delete
Default destructor.
C++ automatic scope transaction class.
Definition: transaction.hpp:188
Custom transaction error class.
Definition: pexceptions.hpp:90
Custom out of memory error class.
Definition: pexceptions.hpp:146
static int add_lock(L &lock, Locks &... locks) noexcept
Recursively add locks to the active transaction.
Definition: transaction.hpp:516
bool new_uncaught_exception()
Notifies is a new exception is being handled.
Definition: transaction.hpp:285
automatic(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:208
uncaught_exception_counter()
Default constructor.
Definition: transaction.hpp:272
Resides on pmem class.
Definition: p.hpp:64
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:43
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:403
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.