38 #ifndef PMEMOBJ_CONDVARIABLE_HPP 39 #define PMEMOBJ_CONDVARIABLE_HPP 42 #include <condition_variable> 46 #include "libpmemobj/thread.h" 63 typedef std::chrono::system_clock clock_type;
90 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
91 if (
int ret = pmemobj_cond_signal(pop, &this->
pcond))
93 "Error notifying one on " 94 "a condition variable.");
105 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
106 if (
int ret = pmemobj_cond_broadcast(pop, &this->
pcond))
108 "Error notifying all on " 109 "a condition variable.");
150 template <
typename Lock>
176 template <
typename Predicate>
204 template <
typename Lock,
typename Predicate>
206 wait(Lock &lock, Predicate pred)
208 this->
wait_impl(*lock.mutex(), std::move(pred));
232 template <
typename Clock,
typename Duration>
235 const std::chrono::time_point<Clock, Duration> &timeout)
263 template <
typename Lock,
typename Clock,
typename Duration>
266 const std::chrono::time_point<Clock, Duration> &timeout)
293 template <
typename Clock,
typename Duration,
typename Predicate>
296 const std::chrono::time_point<Clock, Duration> &timeout,
326 template <
typename Lock,
typename Clock,
typename Duration,
330 const std::chrono::time_point<Clock, Duration> &timeout,
360 template <
typename Lock,
typename Rep,
typename Period>
362 wait_for(Lock &lock,
const std::chrono::duration<Rep, Period> &rel_time)
365 clock_type::now() + rel_time);
392 template <
typename Lock,
typename Rep,
typename Period,
395 wait_for(Lock &lock,
const std::chrono::duration<Rep, Period> &rel_time,
399 clock_type::now() + rel_time,
424 template <
typename Rep,
typename Period>
427 const std::chrono::duration<Rep, Period> &rel_time)
430 clock_type::now() + rel_time);
455 template <
typename Rep,
typename Period,
typename Predicate>
458 const std::chrono::duration<Rep, Period> &rel_time,
493 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
494 if (
int ret = pmemobj_cond_wait(pop, &this->
pcond,
497 "Error waiting on a condition " 504 template <
typename Predicate>
515 template <
typename Clock,
typename Duration>
519 const std::chrono::time_point<Clock, Duration> &abs_timeout)
521 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
524 const typename Clock::time_point their_now = Clock::now();
525 const clock_type::time_point my_now = clock_type::now();
526 const auto delta = abs_timeout - their_now;
527 const auto my_rel = my_now + delta;
529 struct timespec ts = detail::timepoint_to_timespec(my_rel);
531 auto ret = pmemobj_cond_timedwait(pop, &this->
pcond,
535 return std::cv_status::no_timeout;
536 else if (ret == ETIMEDOUT)
537 return std::cv_status::timeout;
540 "Error waiting on a condition " 547 template <
typename Clock,
typename Duration,
typename Predicate>
551 const std::chrono::time_point<Clock, Duration> &abs_timeout,
556 std::cv_status::timeout)
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:549
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: condition_variable.hpp:471
Persistent memory resident condition variable.
Definition: condition_variable.hpp:62
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: mutex.hpp:150
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:362
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:517
Persistent memory resident mutex implementation.
Definition: mutex.hpp:60
condition_variable() noexcept=default
Defaulted constructor.
void wait_impl(mutex &lock, Predicate pred)
Internal implementation of the wait call.
Definition: condition_variable.hpp:506
void wait(mutex &lock, Predicate pred)
Makes the current thread block until the condition variable is notified.
Definition: condition_variable.hpp:178
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:395
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:457
void wait(Lock &lock, Predicate pred)
Makes the current thread block until the condition variable is notified.
Definition: condition_variable.hpp:206
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:234
void notify_all()
Notify and unblock all threads waiting on *this condition.
Definition: condition_variable.hpp:103
Commonly used conversions.
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:295
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:152
PMEMcond pcond
A POSIX style PMEM-resident condition variable.
Definition: condition_variable.hpp:562
Custom lock error class.
Definition: pexceptions.hpp:74
condition_variable & operator=(const condition_variable &)=delete
Deleted assignment operator.
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:329
Definition: condition_variable.hpp:48
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:265
void notify_one()
Notify and unblock one thread waiting on *this condition.
Definition: condition_variable.hpp:88
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:426
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:128
void wait_impl(mutex &lock)
Internal implementation of the wait call.
Definition: condition_variable.hpp:491
PMEMcond * native_handle_type
The handle typedef to the underlying basic type.
Definition: condition_variable.hpp:67