PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
pmem::obj::shared_mutex Class Reference

Persistent memory resident shared_mutex implementation. More...

#include <libpmemobj++/shared_mutex.hpp>

Public Types

typedef PMEMrwlock * native_handle_type
 Implementation defined handle to the native type.
 

Public Member Functions

 shared_mutex ()
 Default constructor. More...
 
 ~shared_mutex ()=default
 Defaulted destructor.
 
void lock ()
 Lock the mutex for exclusive access. More...
 
void lock_shared ()
 Lock the mutex for shared access. More...
 
bool try_lock ()
 Try to lock the mutex for exclusive access, returns regardless if the lock succeeds. More...
 
bool try_lock_shared ()
 Try to lock the mutex for shared access, returns regardless if the lock succeeds. More...
 
void unlock ()
 Unlocks the mutex. More...
 
void unlock_shared ()
 Unlocks the mutex. More...
 
native_handle_type native_handle () noexcept
 Access a native handle to this shared mutex. More...
 
enum pobj_tx_param lock_type () const noexcept
 The type of lock needed for the transaction API. More...
 
shared_mutexoperator= (const shared_mutex &)=delete
 Deleted assignment operator.
 
 shared_mutex (const shared_mutex &)=delete
 Deleted copy constructor.
 

Detailed Description

Persistent memory resident shared_mutex implementation.

This class is an implementation of a PMEM-resident shared_mutex which mimics in behavior the C++11 std::shared_mutex. This class satisfies all requirements of the SharedMutex and StandardLayoutType concepts. The typical usage would be:

#include <mutex>
void
shared_mutex_example()
{
/* pool root structure */
struct root {
};
/* create a pmemobj pool */
auto pop = pmem::obj::pool<root>::create("poolfile", "layout",
PMEMOBJ_MIN_POOL);
auto proot = pop.root();
/* typical usage schemes */
proot->pmutex.lock_shared();
std::unique_lock<pmem::obj::shared_mutex> guard(proot->pmutex);
}
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:694
Persistent memory resident shared_mutex implementation.
Definition: shared_mutex.hpp:32
Persistent smart pointer.
C++ pmemobj pool.
Pmem-resident shared mutex.

Constructor & Destructor Documentation

◆ shared_mutex()

pmem::obj::shared_mutex::shared_mutex ( )
inline

Default constructor.

Exceptions
lock_errorwhen the shared_mutex is not from persistent memory.

Member Function Documentation

◆ lock()

void pmem::obj::shared_mutex::lock ( )
inline

Lock the mutex for exclusive access.

If a different thread already locked this mutex, the calling thread will block. If the same thread tries to lock a mutex it already owns, either in exclusive or shared mode, the behavior is undefined.

Exceptions
lock_errorwhen an error occurs, this includes all system related errors with the underlying implementation of the mutex.

◆ lock_shared()

void pmem::obj::shared_mutex::lock_shared ( )
inline

Lock the mutex for shared access.

If a different thread already locked this mutex for exclusive access, the calling thread will block. If it was locked for shared access by a different thread, the lock will succeed.

The mutex can be locked for shared access multiple times by the same thread. If so, the same number of unlocks must be made to unlock the mutex.

Exceptions
lock_errorwhen an error occurs, this includes all system related errors with the underlying implementation of the mutex.

◆ lock_type()

enum pobj_tx_param pmem::obj::shared_mutex::lock_type ( ) const
inlinenoexcept

The type of lock needed for the transaction API.

Returns
TX_PARAM_RWLOCK

◆ native_handle()

native_handle_type pmem::obj::shared_mutex::native_handle ( )
inlinenoexcept

Access a native handle to this shared mutex.

Returns
a pointer to PMEMmutex.

◆ try_lock()

bool pmem::obj::shared_mutex::try_lock ( )
inline

Try to lock the mutex for exclusive access, returns regardless if the lock succeeds.

If the same thread tries to lock a mutex it already owns either in exclusive or shared mode, the behavior is undefined.

Returns
true on successful lock acquisition, false otherwise.
Exceptions
lock_errorwhen an error occurs, this includes all system related errors with the underlying implementation of the mutex.

◆ try_lock_shared()

bool pmem::obj::shared_mutex::try_lock_shared ( )
inline

Try to lock the mutex for shared access, returns regardless if the lock succeeds.

The mutex can be locked for shared access multiple times by the same thread. If so, the same number of unlocks must be made to unlock the mutex. If the calling thread already owns the mutex in any mode, the behavior is undefined.

Returns
false if a different thread already locked the mutex for exclusive access, true otherwise.
Exceptions
lock_errorwhen an error occurs, this includes all system related errors with the underlying implementation of the mutex.

◆ unlock()

void pmem::obj::shared_mutex::unlock ( )
inline

Unlocks the mutex.

The mutex must be locked for exclusive access by the calling thread, otherwise results in undefined behavior.

◆ unlock_shared()

void pmem::obj::shared_mutex::unlock_shared ( )
inline

Unlocks the mutex.

The mutex must be locked for shared access by the calling thread, otherwise results in undefined behavior.


The documentation for this class was generated from the following file: