PMDK C++ bindings
1.10
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_TIMED_MUTEX_HPP
10 #define LIBPMEMOBJ_CPP_TIMED_MUTEX_HPP
15 #include <libpmemobj/thread.h>
33 typedef std::chrono::system_clock clock_type;
47 if ((pop = pmemobj_pool_by_ptr(&
plock)) ==
nullptr)
49 1, std::generic_category(),
50 "Persistent mutex not from persistent memory.");
52 pmemobj_mutex_zero(pop, &
plock);
74 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
75 if (
int ret = pmemobj_mutex_lock(pop, &this->
plock))
77 "Failed to lock a mutex.")
78 .with_pmemobj_errormsg();
98 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
99 int ret = pmemobj_mutex_trylock(pop, &this->
plock);
103 else if (ret == EBUSY)
107 "Failed to lock a mutex.")
108 .with_pmemobj_errormsg();
128 template <
typename Clock,
typename Duration>
131 const std::chrono::time_point<Clock, Duration> &timeout_time)
153 template <
typename Rep,
typename Period>
155 try_lock_for(
const std::chrono::duration<Rep, Period> &timeout_duration)
170 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
171 int ret = pmemobj_mutex_unlock(pop, &this->
plock);
174 "Failed to unlock a mutex.")
175 .with_pmemobj_errormsg();
203 template <
typename Clock,
typename Duration>
207 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
210 const typename Clock::time_point their_now = Clock::now();
211 const clock_type::time_point my_now = clock_type::now();
212 const auto delta = abs_time - their_now;
213 const auto my_abs = my_now + delta;
217 auto ret = pmemobj_mutex_timedlock(pop, &this->
plock, &ts);
221 else if (ret == ETIMEDOUT)
225 "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:30
Persistent memory namespace.
Definition: allocation_flag.hpp:15
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:72
void unlock()
Unlocks a previously locked mutex.
Definition: timed_mutex.hpp:168
PMEMmutex plock
A POSIX style PMEM-resident timed_mutex.
Definition: timed_mutex.hpp:229
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: timed_mutex.hpp:184
~timed_mutex()=default
Defaulted destructor.
Custom lock error class.
Definition: pexceptions.hpp:82
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:130
timed_mutex()
Default constructor.
Definition: timed_mutex.hpp:44
PMEMmutex * native_handle_type
Implementation defined handle to the native type.
Definition: timed_mutex.hpp:37
bool timedlock_impl(const std::chrono::time_point< Clock, Duration > &abs_time)
Internal implementation of the timed lock call.
Definition: timed_mutex.hpp:205
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:155
Persistent memory resident timed_mutex implementation.
Definition: timed_mutex.hpp:32
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:96