PMDK C++ bindings
1.5.2
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_CONDVARIABLE_HPP
39 #define LIBPMEMOBJ_CPP_CONDVARIABLE_HPP
42 #include <condition_variable>
46 #include <libpmemobj/thread.h>
63 typedef std::chrono::system_clock clock_type;
78 if ((pop = pmemobj_pool_by_ptr(&
pcond)) ==
nullptr)
80 1, std::generic_category(),
81 "Persistent condition variable not from"
82 " persistent memory.");
84 pmemobj_cond_zero(pop, &
pcond);
103 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
104 if (
int ret = pmemobj_cond_signal(pop, &this->
pcond))
106 "Error notifying one on "
107 "a condition variable.");
118 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
119 if (
int ret = pmemobj_cond_broadcast(pop, &this->
pcond))
121 "Error notifying all on "
122 "a condition variable.");
163 template <
typename Lock>
189 template <
typename Predicate>
217 template <
typename Lock,
typename Predicate>
219 wait(Lock &lock, Predicate pred)
221 this->
wait_impl(*lock.mutex(), std::move(pred));
245 template <
typename Clock,
typename Duration>
248 const std::chrono::time_point<Clock, Duration> &timeout)
276 template <
typename Lock,
typename Clock,
typename Duration>
279 const std::chrono::time_point<Clock, Duration> &timeout)
306 template <
typename Clock,
typename Duration,
typename Predicate>
309 const std::chrono::time_point<Clock, Duration> &timeout,
339 template <
typename Lock,
typename Clock,
typename Duration,
343 const std::chrono::time_point<Clock, Duration> &timeout,
373 template <
typename Lock,
typename Rep,
typename Period>
375 wait_for(Lock &lock,
const std::chrono::duration<Rep, Period> &rel_time)
378 clock_type::now() + rel_time);
405 template <
typename Lock,
typename Rep,
typename Period,
408 wait_for(Lock &lock,
const std::chrono::duration<Rep, Period> &rel_time,
412 clock_type::now() + rel_time,
437 template <
typename Rep,
typename Period>
440 const std::chrono::duration<Rep, Period> &rel_time)
443 clock_type::now() + rel_time);
468 template <
typename Rep,
typename Period,
typename Predicate>
471 const std::chrono::duration<Rep, Period> &rel_time,
506 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
507 if (
int ret = pmemobj_cond_wait(pop, &this->
pcond,
510 "Error waiting on a condition "
517 template <
typename Predicate>
528 template <
typename Clock,
typename Duration>
532 const std::chrono::time_point<Clock, Duration> &abs_timeout)
534 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
537 const typename Clock::time_point their_now = Clock::now();
538 const clock_type::time_point my_now = clock_type::now();
539 const auto delta = abs_timeout - their_now;
540 const auto my_rel = my_now + delta;
542 struct timespec ts = detail::timepoint_to_timespec(my_rel);
544 auto ret = pmemobj_cond_timedwait(pop, &this->
pcond,
548 return std::cv_status::no_timeout;
549 else if (ret == ETIMEDOUT)
550 return std::cv_status::timeout;
553 "Error waiting on a condition "
560 template <
typename Clock,
typename Duration,
typename Predicate>
564 const std::chrono::time_point<Clock, Duration> &abs_timeout,
569 std::cv_status::timeout)
std::cv_status wait_until(mutex &lock, const std::chrono::time_point< Clock, Duration > &timeout)
Makes the current thread block until the condition variable is notified, a specific time is reached o...
Definition: condition_variable.hpp:247
std::cv_status wait_for(mutex &lock, const std::chrono::duration< Rep, Period > &rel_time)
Makes the current thread block until the condition variable is notified, the specified amount of time...
Definition: condition_variable.hpp:439
std::cv_status wait_for(Lock &lock, const std::chrono::duration< Rep, Period > &rel_time)
Makes the current thread block until the condition variable is notified, the specified amount of time...
Definition: condition_variable.hpp:375
Persistent memory resident mutex implementation.
Definition: mutex.hpp:60
bool wait_for(mutex &lock, const std::chrono::duration< Rep, Period > &rel_time, Predicate pred)
Makes the current thread block until the condition variable is notified or the specified amount of ti...
Definition: condition_variable.hpp:470
PMEMcond pcond
A POSIX style PMEM-resident condition variable.
Definition: condition_variable.hpp:575
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: mutex.hpp:158
Commonly used conversions.
condition_variable()
Default constructor.
Definition: condition_variable.hpp:75
std::cv_status wait_until_impl(mutex &lock, const std::chrono::time_point< Clock, Duration > &abs_timeout)
Internal implementation of the wait_until call.
Definition: condition_variable.hpp:530
void wait(mutex &lock)
Makes the current thread block until the condition variable is notified or it is woken up by some oth...
Definition: condition_variable.hpp:141
void notify_one()
Notify and unblock one thread waiting on *this condition.
Definition: condition_variable.hpp:101
condition_variable & operator=(const condition_variable &)=delete
Deleted assignment operator.
void wait(mutex &lock, Predicate pred)
Makes the current thread block until the condition variable is notified.
Definition: condition_variable.hpp:191
void wait_impl(mutex &lock, Predicate pred)
Internal implementation of the wait call.
Definition: condition_variable.hpp:519
Custom lock error class.
Definition: pexceptions.hpp:74
void wait(Lock &lock, Predicate pred)
Makes the current thread block until the condition variable is notified.
Definition: condition_variable.hpp:219
std::cv_status wait_until(Lock &lock, const std::chrono::time_point< Clock, Duration > &timeout)
Makes the current thread block until the condition variable is notified, a specific time is reached o...
Definition: condition_variable.hpp:278
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: condition_variable.hpp:484
condition_variable(const condition_variable &)=delete
Deleted copy constructor.
PMEMcond * native_handle_type
The handle typedef to the underlying basic type.
Definition: condition_variable.hpp:67
void wait_impl(mutex &lock)
Internal implementation of the wait call.
Definition: condition_variable.hpp:504
Persistent memory resident condition variable.
Definition: condition_variable.hpp:62
~condition_variable()=default
Defaulted destructor.
bool wait_until_impl(mutex &lock, const std::chrono::time_point< Clock, Duration > &abs_timeout, Predicate pred)
Internal implementation of the wait_until call.
Definition: condition_variable.hpp:562
void notify_all()
Notify and unblock all threads waiting on *this condition.
Definition: condition_variable.hpp:116
bool wait_until(mutex &lock, const std::chrono::time_point< Clock, Duration > &timeout, Predicate pred)
Makes the current thread block until the condition variable is notified or a specific time is reached...
Definition: condition_variable.hpp:308
bool wait_for(Lock &lock, const std::chrono::duration< Rep, Period > &rel_time, Predicate pred)
Makes the current thread block until the condition variable is notified or the specified amount of ti...
Definition: condition_variable.hpp:408
bool wait_until(Lock &lock, const std::chrono::time_point< Clock, Duration > &timeout, Predicate pred)
Makes the current thread block until the condition variable is notified or a specific time is reached...
Definition: condition_variable.hpp:342
void wait(Lock &lock)
Makes the current thread block until the condition variable is notified or it is woken up by some oth...
Definition: condition_variable.hpp:165