PMDK C++ bindings
1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_TIMED_MUTEX_HPP
39 #define LIBPMEMOBJ_CPP_TIMED_MUTEX_HPP
44 #include <libpmemobj/thread.h>
62 typedef std::chrono::system_clock clock_type;
76 if ((pop = pmemobj_pool_by_ptr(&
plock)) ==
nullptr)
78 1, std::generic_category(),
79 "Persistent mutex not from persistent memory.");
81 pmemobj_mutex_zero(pop, &
plock);
103 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
104 if (
int ret = pmemobj_mutex_lock(pop, &this->
plock))
106 "Failed to lock a mutex.")
107 .with_pmemobj_errormsg();
127 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
128 int ret = pmemobj_mutex_trylock(pop, &this->
plock);
132 else if (ret == EBUSY)
136 "Failed to lock a mutex.")
137 .with_pmemobj_errormsg();
157 template <
typename Clock,
typename Duration>
160 const std::chrono::time_point<Clock, Duration> &timeout_time)
182 template <
typename Rep,
typename Period>
184 try_lock_for(
const std::chrono::duration<Rep, Period> &timeout_duration)
199 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
200 int ret = pmemobj_mutex_unlock(pop, &this->
plock);
203 "Failed to unlock a mutex.")
204 .with_pmemobj_errormsg();
232 template <
typename Clock,
typename Duration>
236 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
239 const typename Clock::time_point their_now = Clock::now();
240 const clock_type::time_point my_now = clock_type::now();
241 const auto delta = abs_time - their_now;
242 const auto my_abs = my_now + delta;
246 auto ret = pmemobj_mutex_timedlock(pop, &this->
plock, &ts);
250 else if (ret == ETIMEDOUT)
254 "Failed to lock a mutex");
timespec timepoint_to_timespec(const std::chrono::time_point< Clock, Duration > &timepoint)
Convert std::chrono::time_point to posix timespec.
Definition: conversions.hpp:59
Persistent memory namespace.
Definition: allocation_flag.hpp:44
Commonly used conversions.
timed_mutex(const timed_mutex &)=delete
Deleted copy constructor.
void lock()
Locks the mutex, blocks if already locked.
Definition: timed_mutex.hpp:101
void unlock()
Unlocks a previously locked mutex.
Definition: timed_mutex.hpp:197
PMEMmutex plock
A POSIX style PMEM-resident timed_mutex.
Definition: timed_mutex.hpp:258
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: timed_mutex.hpp:213
~timed_mutex()=default
Defaulted destructor.
Custom lock error class.
Definition: pexceptions.hpp:111
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.
Definition: timed_mutex.hpp:159
timed_mutex()
Default constructor.
Definition: timed_mutex.hpp:73
PMEMmutex * native_handle_type
Implementation defined handle to the native type.
Definition: timed_mutex.hpp:66
bool timedlock_impl(const std::chrono::time_point< Clock, Duration > &abs_time)
Internal implementation of the timed lock call.
Definition: timed_mutex.hpp:234
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.
Definition: timed_mutex.hpp:184
Persistent memory resident timed_mutex implementation.
Definition: timed_mutex.hpp:61
timed_mutex & operator=(const timed_mutex &)=delete
Deleted assignment operator.
bool try_lock()
Tries to lock the mutex, returns regardless if the lock succeeds.
Definition: timed_mutex.hpp:125