PMDK C++ bindings  1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Member Functions | List of all members
pmem::obj::transaction::manual Class Reference

C++ manual scope transaction class. More...

#include <libpmemobj++/transaction.hpp>

Public Member Functions

template<typename... L>
 manual (obj::pool_base &pop, L &... locks)
 RAII constructor with pmem resident locks. More...
 
 ~manual () noexcept
 Destructor. More...
 
 manual (const manual &p)=delete
 Deleted copy constructor.
 
 manual (const manual &&p)=delete
 Deleted move constructor.
 
manualoperator= (const manual &p)=delete
 Deleted assignment operator.
 
manualoperator= (manual &&p)=delete
 Deleted move assignment operator.
 

Detailed Description

C++ manual scope transaction class.

This class is one of pmemobj transaction handlers. All operations between creating and destroying the transaction object are treated as performed in a transaction block and can be rolled back. The manual transaction has to be committed explicitly otherwise it will abort.

The locks are held for the entire duration of the transaction. They are released at the end of the scope, so within the catch block, they are already unlocked. If the cleanup action requires access to data within a critical section, the locks have to be manually acquired once again.

The typical usage example would be:

using namespace pmem::obj;
int
manual_tx_example()
{
// pool root structure
struct root {
mutex pmutex;
shared_mutex shared_pmutex;
p<int> count;
persistent_ptr<root> another_root;
};
// create a pmemobj pool
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.root();
try {
transaction::manual tx(pop, proot->pmutex,
proot->shared_pmutex);
// atomically allocate objects
proot->another_root = make_persistent<root>();
// atomically modify objects
proot->count++;
// It's necessary to commit the transaction manually and
// it has to be the last operation in the transaction.
// an internal transaction error occurred, tx aborted
// reacquire locks if necessary
} catch (...) {
// some other exception thrown, tx aborted
// reacquire locks if necessary
}
// In complex cases with library calls, remember to check the status of
// the previous transaction.
return transaction::error();
}

Constructor & Destructor Documentation

◆ manual()

template<typename... L>
pmem::obj::transaction::manual::manual ( obj::pool_base pop,
L &...  locks 
)
inline

RAII constructor with pmem resident locks.

Start pmemobj transaction and add list of locks to new transaction. The list of locks may be empty.

Parameters
[in,out]poppool object.
[in,out]lockslocks of obj::mutex or obj::shared_mutex type.
Exceptions
pmem::transaction_errorwhen pmemobj_tx_begin function or locks adding failed.

◆ ~manual()

pmem::obj::transaction::manual::~manual ( )
inlinenoexcept

Destructor.

End pmemobj transaction. If the transaction has not been committed before object destruction, an abort will be issued.


The documentation for this class was generated from the following file:
pmem::obj::transaction::commit
static void commit()
Manually commit a transaction.
Definition: transaction.hpp:369
pmem::obj::mutex
Persistent memory resident mutex implementation.
Definition: mutex.hpp:60
pmem::obj::pool::create
static pool< T > create(const std::string &path, const std::string &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:701
pmem::transaction_error
Custom transaction error class.
Definition: pexceptions.hpp:92
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
pmem::obj::pool::root
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:651
pool.hpp
C++ pmemobj pool.
make_persistent.hpp
Persistent_ptr transactional allocation functions for objects.
pmem::obj
Main libpmemobj namespace.
Definition: allocation_flag.hpp:47
transaction.hpp
C++ pmemobj transactions.
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:212
shared_mutex.hpp
Pmem-resident shared mutex.
pext.hpp
Convenience extensions for the resides on pmem property template.
persistent_ptr.hpp
Persistent smart pointer.
pmem::obj::shared_mutex
Persistent memory resident shared_mutex implementation.
Definition: shared_mutex.hpp:59
pmem::obj::transaction::manual
C++ manual scope transaction class.
Definition: transaction.hpp:100
mutex.hpp
Pmem-resident mutex.