Persistent memory resident timed_mutex implementation.
More...
#include <libpmemobj++/timed_mutex.hpp>
|
| 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_mutex & | operator= (const timed_mutex &)=delete |
| Deleted assignment operator.
|
|
| timed_mutex (const timed_mutex &)=delete |
| Deleted copy constructor.
|
|
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>
void
timed_mutex_example()
{
struct root {
};
PMEMOBJ_MIN_POOL);
auto proot = pop.root();
const auto timeout = std::chrono::milliseconds(100);
proot->pmutex.try_lock_for(timeout);
proot->pmutex.try_lock_until(std::chrono::steady_clock::now() +
timeout);
}
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 timed_mutex implementation.
Definition: timed_mutex.hpp:34
Persistent smart pointer.
Pmem-resident timed_mutex.
◆ timed_mutex()
pmem::obj::timed_mutex::timed_mutex |
( |
| ) |
|
|
inline |
Default constructor.
- Exceptions
-
◆ 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_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex. |
◆ native_handle()
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_error | when 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_duration | a specific duration, which when expired unblocks the thread. |
- Returns
true
on successful lock acquisition, false
otherwise.
- Exceptions
-
lock_error | when 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_time | a specific point in time, which when reached unblocks the thread. |
- Returns
true
on successful lock acquisition, false
otherwise.
- Exceptions
-
lock_error | when 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.
The documentation for this class was generated from the following file: