18 #ifndef FOEDUS_THREAD_CONDITION_VARIABLE_IMPL_HPP_
19 #define FOEDUS_THREAD_CONDITION_VARIABLE_IMPL_HPP_
24 #include <condition_variable>
63 while (notifiers_ > 0) {
79 template<
typename PREDICATE>
80 void wait(PREDICATE predicate) {
81 WaiterScope scope(
this);
82 condition_.wait(scope.lock_, predicate);
90 WaiterScope scope(
this);
91 condition_.wait(scope.lock_);
100 template<
class REP,
class PERIOD,
typename PREDICATE>
101 bool wait_for(
const std::chrono::duration<REP, PERIOD>& timeout, PREDICATE predicate) {
102 WaiterScope scope(
this);
103 return condition_.wait_for(scope.lock_, timeout, predicate);
112 template<
class REP,
class PERIOD>
113 bool wait_for(
const std::chrono::duration<REP, PERIOD>& timeout) {
114 WaiterScope scope(
this);
115 return condition_.wait_for(scope.lock_, timeout) == std::cv_status::no_timeout;
124 template<
class CLOCK,
class DURATION,
typename PREDICATE>
125 bool wait_until(
const std::chrono::time_point<CLOCK, DURATION>& until, PREDICATE predicate) {
126 WaiterScope scope(
this);
127 return condition_.wait_until(scope.lock_, until, predicate);
136 template<
class CLOCK,
class DURATION>
137 bool wait_until(
const std::chrono::time_point<CLOCK, DURATION>& until) {
138 WaiterScope scope(
this);
139 return condition_.wait_until(scope.lock_, until) == std::cv_status::no_timeout;
152 template<
typename SIGNAL_ACTION>
154 NotifierScope scope(
this);
156 std::lock_guard<std::mutex> guard(mutex_);
159 while (waiters_ > 0) {
160 condition_.notify_one();
186 template<
typename SIGNAL_ACTION>
188 NotifierScope scope(
this);
190 std::lock_guard<std::mutex> guard(mutex_);
194 condition_.notify_one();
212 std::condition_variable condition_;
221 std::atomic<uint32_t> waiters_;
223 std::atomic<uint32_t> notifiers_;
228 : enclosure_(enclosure), lock_(enclosure_->mutex_) {
230 ++enclosure_->waiters_;
235 --enclosure_->waiters_;
238 std::unique_lock<std::mutex> lock_;
241 struct NotifierScope {
243 ++enclosure_->notifiers_;
247 --enclosure_->notifiers_;
256 #endif // FOEDUS_THREAD_CONDITION_VARIABLE_IMPL_HPP_
ConditionVariable & operator=(const ConditionVariable &other)=delete
void notify_all(SIGNAL_ACTION signal_action)
Notify all waiters that the event has happened.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
void notify_one()
Notify one waiter that the event has happened.
bool wait_for(const std::chrono::duration< REP, PERIOD > &timeout)
Block until the event happens or the given period elapses.
void notify_all()
Notify all waiters that the event has happened.
bool wait_for(const std::chrono::duration< REP, PERIOD > &timeout, PREDICATE predicate)
Block until the event happens or the given period elapses.
An analogue of pthread's condition variable and std::condition_variable to avoid glibc's bug in pthre...
void spinlock_yield()
Invoke _mm_pause(), x86 PAUSE instruction, or something equivalent in the env.
bool wait_until(const std::chrono::time_point< CLOCK, DURATION > &until)
Block until the event happens or the given time point arrives.
void wait()
Block until the event PROBABLY (because this version is w/o pred) happens.
bool wait_until(const std::chrono::time_point< CLOCK, DURATION > &until, PREDICATE predicate)
Block until the event happens or the given time point arrives.
void wait(PREDICATE predicate)
Block until the event happens.
void notify_one(SIGNAL_ACTION signal_action)
Notify one waiter that the event has happened.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...