PMDK C++ bindings  1.8.2
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
pmem::obj::timed_mutex Class Reference

Persistent memory resident timed_mutex implementation. More...

#include <libpmemobj++/timed_mutex.hpp>

Public Types

typedef PMEMmutex * native_handle_type
 Implementation defined handle to the native type. More...
 

Public Member Functions

 timed_mutex ()
 Default constructor. More...
 
 ~timed_mutex ()=default
 Defaulted destructor.
 
void lock ()
 Locks the mutex, blocks if already locked. More...
 
bool try_lock ()
 Tries to lock the mutex, returns regardless if the lock succeeds. More...
 
template<typename Clock , typename Duration >
bool try_lock_until (const std::chrono::time_point< Clock, Duration > &timeout_time)
 Makes the current thread block until the lock is acquired or a specific time is reached. More...
 
template<typename Rep , typename Period >
bool try_lock_for (const std::chrono::duration< Rep, Period > &timeout_duration)
 Makes the current thread block until the lock is acquired or a specified amount of time passes. More...
 
void unlock ()
 Unlocks a previously locked mutex. More...
 
native_handle_type native_handle () noexcept
 Access a native handle to this condition variable. More...
 
timed_mutexoperator= (const timed_mutex &)=delete
 Deleted assignment operator.
 
 timed_mutex (const timed_mutex &)=delete
 Deleted copy constructor.
 

Private Member Functions

template<typename Clock , typename Duration >
bool timedlock_impl (const std::chrono::time_point< Clock, Duration > &abs_time)
 Internal implementation of the timed lock call.
 

Private Attributes

PMEMmutex plock
 A POSIX style PMEM-resident timed_mutex. More...
 

Detailed Description

Persistent memory resident timed_mutex implementation.

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

#include <chrono>
namespace nvobj = pmem::obj;
void
timed_mutex_example()
{
// pool root structure
struct root {
nvobj::timed_mutex pmutex;
};
// create a pmemobj pool
auto pop = nvobj::pool<root>::create("poolfile", "layout",
PMEMOBJ_MIN_POOL);
auto proot = pop.root();
const auto timeout = std::chrono::milliseconds(100);
// typical usage schemes
proot->pmutex.try_lock_for(timeout);
proot->pmutex.try_lock_until(std::chrono::steady_clock::now() +
timeout);
}

Member Typedef Documentation

◆ native_handle_type

Implementation defined handle to the native type.

Constructor & Destructor Documentation

◆ timed_mutex()

pmem::obj::timed_mutex::timed_mutex ( )
inline

Default constructor.

Exceptions
lock_errorwhen the timed_mutex is not from persistent memory.

Member Function Documentation

◆ lock()

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

Locks the mutex, blocks if already locked.

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, the behavior is undefined.

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

◆ native_handle()

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

Access a native handle to this condition variable.

Returns
a pointer to PMEMmutex.

◆ try_lock()

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

Tries to lock the mutex, returns regardless if the lock succeeds.

If the same thread tries to lock a mutex it already owns, 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_for()

template<typename Rep , typename Period >
bool pmem::obj::timed_mutex::try_lock_for ( const std::chrono::duration< Rep, Period > &  timeout_duration)
inline

Makes the current thread block until the lock is acquired or a specified amount of time passes.

If the same thread tries to lock a mutex it already owns, the behavior is undefined.

Parameters
[in]timeout_durationa specific duration, which when expired unblocks the thread.
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_until()

template<typename Clock , typename Duration >
bool pmem::obj::timed_mutex::try_lock_until ( const std::chrono::time_point< Clock, Duration > &  timeout_time)
inline

Makes the current thread block until the lock is acquired or a specific time is reached.

If the same thread tries to lock a mutex it already owns, the behavior is undefined.

Parameters
[in]timeout_timea specific point in time, which when reached unblocks the thread.
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.

◆ unlock()

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

Unlocks a previously locked mutex.

Unlocking a mutex that has not been locked by the current thread results in undefined behavior. Unlocking a mutex that has not been lock also results in undefined behavior.

Member Data Documentation

◆ plock

PMEMmutex pmem::obj::timed_mutex::plock
private

A POSIX style PMEM-resident timed_mutex.


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