libfoedus-core
FOEDUS Core Library
|
An analogue of pthread's condition variable and std::condition_variable to avoid glibc's bug in pthread_cond_broadcast/signal (thus in notify_all/one in turn). More...
An analogue of pthread's condition variable and std::condition_variable to avoid glibc's bug in pthread_cond_broadcast/signal (thus in notify_all/one in turn).
The whole purpose of this class is to workaound a bug in glibc's pthread_cond_broadcast/signal(), which is also used by std::condition_variable.
The bug is already fixed here: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=8f630cca5c36941db1cb48726016bbed80ec1041 However, it will not be available until glibc 2.20, which will be employed in major linux distros much much later. So, we work around the issue ourselves for a while.
Seems like the issue is not only about broadcast. I'm observing issues if we might call notify_one while there is no waiter (which should be totally valid, but then something gets occasionally broken.) So, whether you have at most one waiter not, we should use this class always. Do not use std::condition_variable at all.
As this depends on C++11, the name of this file ends with impl. Thus, only private implementation classes directly use this class. If you are okay with C++11, you can use it from client programs, too.
This class is totally header-only.
Definition at line 56 of file condition_variable_impl.hpp.
#include <condition_variable_impl.hpp>
Public Member Functions | |
ConditionVariable () | |
~ConditionVariable () | |
ConditionVariable (const ConditionVariable &other)=delete | |
ConditionVariable & | operator= (const ConditionVariable &other)=delete |
ConditionVariable (ConditionVariable &&other)=delete | |
ConditionVariable & | operator= (ConditionVariable &&other)=delete |
template<typename PREDICATE > | |
void | wait (PREDICATE predicate) |
Block until the event happens. More... | |
void | wait () |
Block until the event PROBABLY (because this version is w/o pred) happens. More... | |
template<class REP , class PERIOD , typename PREDICATE > | |
bool | wait_for (const std::chrono::duration< REP, PERIOD > &timeout, PREDICATE predicate) |
Block until the event happens or the given period elapses. More... | |
template<class REP , class PERIOD > | |
bool | wait_for (const std::chrono::duration< REP, PERIOD > &timeout) |
Block until the event happens or the given period elapses. More... | |
template<class CLOCK , class DURATION , typename PREDICATE > | |
bool | wait_until (const std::chrono::time_point< CLOCK, DURATION > &until, PREDICATE predicate) |
Block until the event happens or the given time point arrives. More... | |
template<class CLOCK , class DURATION > | |
bool | wait_until (const std::chrono::time_point< CLOCK, DURATION > &until) |
Block until the event happens or the given time point arrives. More... | |
template<typename SIGNAL_ACTION > | |
void | notify_all (SIGNAL_ACTION signal_action) |
Notify all waiters that the event has happened. More... | |
void | notify_all () |
Notify all waiters that the event has happened. More... | |
template<typename SIGNAL_ACTION > | |
void | notify_one (SIGNAL_ACTION signal_action) |
Notify one waiter that the event has happened. More... | |
void | notify_one () |
Notify one waiter that the event has happened. More... | |
|
inline |
Definition at line 58 of file condition_variable_impl.hpp.
|
inline |
Definition at line 59 of file condition_variable_impl.hpp.
References ASSERT_ND, and foedus::assorted::spinlock_yield().
|
delete |
|
delete |
|
inline |
Notify all waiters that the event has happened.
[in] | signal_action | Functor to update actual values that changes the condition variable to signaling state. This will be executed in critical section to avoid lost signal and spurious wakeup. |
Equivalent to std::condition_variable::notify_all(). To workaround the pthread_cond_broadcast bug, this method notifies one by one. We might add a switch of the behavior by checking glibc version.
Definition at line 153 of file condition_variable_impl.hpp.
References foedus::assorted::spinlock_yield().
Referenced by foedus::thread::Rendezvous::signal().
|
inline |
Notify all waiters that the event has happened.
Equivalent to std::condition_variable::notify_all(). To workaround the pthread_cond_broadcast bug, this method notifies one by one. We might add a switch of the behavior by checking glibc version.
Definition at line 171 of file condition_variable_impl.hpp.
|
inline |
Notify one waiter that the event has happened.
[in] | signal_action | Functor to update actual values that changes the condition variable to signaling state. This will be executed in critical section to avoid lost signal and spurious wakeup. |
Equivalent to std::condition_variable::notify_one(). To workaround the pthread_cond_signal bug, this method atomically checks if there is any waiter, avoiding to call notify_one() if there is none. We might add a switch of the behavior by checking glibc version.
Definition at line 187 of file condition_variable_impl.hpp.
Referenced by foedus::thread::StoppableThread::request_stop(), and foedus::thread::StoppableThread::wakeup().
|
inline |
Notify one waiter that the event has happened.
Equivalent to std::condition_variable::notify_one(). To workaround the pthread_cond_signal bug, this method atomically checks if there is any waiter, avoiding to call notify_one() if there is none. We might add a switch of the behavior by checking glibc version.
Definition at line 206 of file condition_variable_impl.hpp.
|
delete |
|
delete |
|
inline |
Block until the event happens.
Equivalent to std::condition_variable::wait().
Definition at line 80 of file condition_variable_impl.hpp.
Referenced by foedus::thread::Rendezvous::wait().
|
inline |
Block until the event PROBABLY (because this version is w/o pred) happens.
Equivalent to std::condition_variable::wait().
Definition at line 89 of file condition_variable_impl.hpp.
|
inline |
Block until the event happens or the given period elapses.
Equivalent to std::condition_variable::wait_for().
Definition at line 101 of file condition_variable_impl.hpp.
Referenced by foedus::thread::StoppableThread::sleep(), and foedus::thread::Rendezvous::wait_for().
|
inline |
Block until the event happens or the given period elapses.
Equivalent to std::condition_variable::wait_for().
Definition at line 113 of file condition_variable_impl.hpp.
|
inline |
Block until the event happens or the given time point arrives.
Equivalent to std::condition_variable::wait_until().
Definition at line 125 of file condition_variable_impl.hpp.
Referenced by foedus::thread::Rendezvous::wait_until().
|
inline |
Block until the event happens or the given time point arrives.
Equivalent to std::condition_variable::wait_until().
Definition at line 137 of file condition_variable_impl.hpp.