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);
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))
282 return std::uncaught_exceptions() > this->
count;
326 if (pmemobj_tx_stage() != TX_STAGE_WORK)
329 pmemobj_tx_abort(err);
346 if (pmemobj_tx_stage() != TX_STAGE_WORK)
355 return pmemobj_tx_errno();
358 POBJ_CPP_DEPRECATED
static int 359 get_last_tx_error() noexcept
361 return transaction::error();
395 template <
typename... Locks>
399 if (pmemobj_tx_begin(
pool.
handle(),
nullptr, TX_PARAM_NONE) !=
406 pmemobj_tx_abort(err);
407 (void)pmemobj_tx_end();
409 "failed to add a lock to the transaction");
415 (void)pmemobj_tx_end();
419 if (pmemobj_tx_stage() == TX_STAGE_WORK)
420 pmemobj_tx_abort(ECANCELED);
423 (void)pmemobj_tx_end();
427 auto stage = pmemobj_tx_stage();
429 if (stage == TX_STAGE_WORK) {
431 }
else if (stage == TX_STAGE_ONABORT) {
432 (void)pmemobj_tx_end();
434 }
else if (stage == TX_STAGE_NONE) {
436 "transaction ended prematurely");
439 (void)pmemobj_tx_end();
442 template <
typename... Locks>
443 POBJ_CPP_DEPRECATED
static void 444 exec_tx(
pool_base &
pool, std::function<
void()> tx, Locks &... locks)
468 template <
typename T,
469 typename std::enable_if<IS_TRIVIALLY_COPYABLE(T), T>::type * =
474 if (TX_STAGE_WORK != pmemobj_tx_stage())
476 "wrong stage for taking a snapshot.");
478 if (pmemobj_tx_add_range_direct(addr,
sizeof(*addr) * num))
480 "Could not take a snapshot of given memory range.");
496 template <
typename L,
typename... Locks>
501 pmemobj_tx_lock(lock.lock_type(), lock.native_handle());
int count
The number of active exceptions.
Definition: transaction.hpp:289
static int add_lock() noexcept
Method ending the recursive algorithm.
Definition: transaction.hpp:513
The non-template pool base class.
Definition: pool.hpp:67
Internal class for counting active exceptions.
Definition: transaction.hpp:259
~manual() noexcept
Destructor.
Definition: transaction.hpp:130
~automatic() noexcept(false)
Destructor.
Definition: transaction.hpp:219
C++ transaction handler class.
Definition: transaction.hpp:72
Custom transaction error class.
Definition: pexceptions.hpp:114
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 ...
Definition: transaction.hpp:472
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:344
static void abort(int err)
Manually abort the current transaction.
Definition: transaction.hpp:324
~transaction() noexcept=delete
Default destructor.
C++ automatic scope transaction class.
Definition: transaction.hpp:184
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:498
bool new_uncaught_exception()
Notifies is a new exception is being handled.
Definition: transaction.hpp:280
automatic(obj::pool_base &pop, L &... locks)
RAII constructor with pmem resident locks.
Definition: transaction.hpp:204
uncaught_exception_counter()
Default constructor.
Definition: transaction.hpp:267
Resides on pmem class.
Definition: p.hpp:64
Definition: allocator.hpp:48
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:397
automatic & operator=(const automatic &p)=delete
Deleted assignment operator.