NVML C++ bindings  0.1 experimental
This is the C++ bindings documentation for NVML's libpmemobj.
Public Types | Public Member Functions | Private Attributes | List of all members
nvml::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 () noexcept=default
 Defaulted constructor.
 
 ~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_lock 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 = nvml::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, S_IWUSR | S_IRUSR);
auto proot = pop.get_root();
// typical usage schemes
proot->pmutex.lock_shared();
std::unique_lock<nvobj::shared_mutex> guard(proot->pmutex);
}

Member Typedef Documentation

Implementation defined handle to the native type.

Member Function Documentation

void nvml::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.
void nvml::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.
enum pobj_tx_lock nvml::obj::shared_mutex::lock_type ( ) const
inlinenoexcept

The type of lock needed for the transaction API.

Returns
TX_LOCK_RWLOCK
native_handle_type nvml::obj::shared_mutex::native_handle ( )
inlinenoexcept

Access a native handle to this shared mutex.

Returns
a pointer to PMEMmutex.
bool nvml::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.
bool nvml::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.
void nvml::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.

Exceptions
lock_errorwhen an error occurs, this includes all system related errors with the underlying implementation of the mutex.
void nvml::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.

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

Member Data Documentation

PMEMrwlock nvml::obj::shared_mutex::plock
private

A POSIX style PMEM-resident shared_mutex.


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