PMDK C++ bindings  1.7.1
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Types | Public Member Functions | Private Attributes | List of all members
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. More...
 

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.
 

Private Attributes

PMEMrwlock plock
 A POSIX style PMEM-resident shared_mutex. More...
 

Detailed Description

Persistent memory resident shared_mutex implementation.

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

#include <mutex>
namespace nvobj = pmem::obj;
void
shared_mutex_example()
{
// pool root structure
struct root {
nvobj::shared_mutex pmutex;
};
// create a pmemobj pool
auto pop = nvobj::pool<root>::create("poolfile", "layout",
PMEMOBJ_MIN_POOL);
auto proot = pop.root();
// typical usage schemes
proot->pmutex.lock_shared();
std::unique_lock<nvobj::shared_mutex> guard(proot->pmutex);
}

Member Typedef Documentation

◆ native_handle_type

Implementation defined handle to the native type.

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.

Member Data Documentation

◆ plock

PMEMrwlock pmem::obj::shared_mutex::plock
private

A POSIX style PMEM-resident shared_mutex.


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