PMDK C++ bindings
1.8.1
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 persistent memory.");
83 pmemobj_cond_zero(pop, &
pcond);
102 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
103 if (
int ret = pmemobj_cond_signal(pop, &this->
pcond))
105 ret, std::system_category(),
106 "Error notifying one on a condition variable.")
107 .with_pmemobj_errormsg();
118 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
119 if (
int ret = pmemobj_cond_broadcast(pop, &this->
pcond))
121 ret, std::system_category(),
122 "Error notifying all on a condition variable.")
123 .with_pmemobj_errormsg();
164 template <
typename Lock>
190 template <
typename Predicate>
218 template <
typename Lock,
typename Predicate>
220 wait(Lock &lock, Predicate pred)
222 this->
wait_impl(*lock.mutex(), std::move(pred));
246 template <
typename Clock,
typename Duration>
249 const std::chrono::time_point<Clock, Duration> &timeout)
277 template <
typename Lock,
typename Clock,
typename Duration>
280 const std::chrono::time_point<Clock, Duration> &timeout)
307 template <
typename Clock,
typename Duration,
typename Predicate>
310 const std::chrono::time_point<Clock, Duration> &timeout,
340 template <
typename Lock,
typename Clock,
typename Duration,
344 const std::chrono::time_point<Clock, Duration> &timeout,
374 template <
typename Lock,
typename Rep,
typename Period>
376 wait_for(Lock &lock,
const std::chrono::duration<Rep, Period> &rel_time)
379 clock_type::now() + rel_time);
406 template <
typename Lock,
typename Rep,
typename Period,
409 wait_for(Lock &lock,
const std::chrono::duration<Rep, Period> &rel_time,
413 clock_type::now() + rel_time,
438 template <
typename Rep,
typename Period>
441 const std::chrono::duration<Rep, Period> &rel_time)
444 clock_type::now() + rel_time);
469 template <
typename Rep,
typename Period,
typename Predicate>
472 const std::chrono::duration<Rep, Period> &rel_time,
507 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
508 if (
int ret = pmemobj_cond_wait(pop, &this->
pcond,
511 ret, std::system_category(),
512 "Error waiting on a condition variable.")
513 .with_pmemobj_errormsg();
519 template <
typename Predicate>
530 template <
typename Clock,
typename Duration>
534 const std::chrono::time_point<Clock, Duration> &abs_timeout)
536 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
539 const typename Clock::time_point their_now = Clock::now();
540 const clock_type::time_point my_now = clock_type::now();
541 const auto delta = abs_timeout - their_now;
542 const auto my_rel = my_now + delta;
544 struct timespec ts = detail::timepoint_to_timespec(my_rel);
546 auto ret = pmemobj_cond_timedwait(pop, &this->
pcond,
550 return std::cv_status::no_timeout;
551 else if (ret == ETIMEDOUT)
552 return std::cv_status::timeout;
555 ret, std::system_category(),
556 "Error waiting on a condition variable.")
557 .with_pmemobj_errormsg();
563 template <
typename Clock,
typename Duration,
typename Predicate>
567 const std::chrono::time_point<Clock, Duration> &abs_timeout,
572 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:248
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:440
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:376
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:471
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:44
PMEMcond pcond
A POSIX style PMEM-resident condition variable.
Definition: condition_variable.hpp:578
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: mutex.hpp:161
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:532
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:142
void notify_one()
Notify and unblock one thread waiting on *this condition.
Definition: condition_variable.hpp:100
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:192
void wait_impl(mutex &lock, Predicate pred)
Internal implementation of the wait call.
Definition: condition_variable.hpp:521
Custom lock error class.
Definition: pexceptions.hpp:109
void wait(Lock &lock, Predicate pred)
Makes the current thread block until the condition variable is notified.
Definition: condition_variable.hpp:220
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:279
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: condition_variable.hpp:485
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:505
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:565
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:309
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:409
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:343
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:166