libfoedus-core
FOEDUS Core Library
|
A conditional variable that can be placed in shared memory and used from multiple processes. More...
A conditional variable that can be placed in shared memory and used from multiple processes.
Analogous to SharedMutex. This is for conditional variable. This class also avoids the pthread bug described in foedus::thread::ConditionVariable. This file does not assume C++11.
Definition at line 39 of file shared_cond.hpp.
#include <shared_cond.hpp>
Public Member Functions | |
SharedCond () | |
~SharedCond () | |
SharedCond (const SharedCond &)=delete | |
SharedCond & | operator= (const SharedCond &)=delete |
void | initialize () |
void | uninitialize () |
bool | is_initialized () const |
void | wait (SharedMutexScope *scope) |
Unconditionally wait for the event. More... | |
bool | timedwait (SharedMutexScope *scope, uint64_t timeout_nanosec) |
Wait for the event up to the given timeout. More... | |
void | broadcast (SharedMutexScope *scope) |
Unblock all waiters. More... | |
void | broadcast_nolock () |
Unblock all waiters without a mutex held by the signaller. More... | |
void | signal (SharedMutexScope *scope) |
Unblock one waiter. More... | |
SharedMutex * | get_mutex () |
Returns the mutex that protects this condition variable. More... | |
bool | exists_waiters () const |
A non-synchronized method to tell seemingly whether there is a waiter or not. More... | |
|
inline |
Definition at line 41 of file shared_cond.hpp.
References initialize().
|
inline |
Definition at line 42 of file shared_cond.hpp.
References uninitialize().
|
delete |
void foedus::soc::SharedCond::broadcast | ( | SharedMutexScope * | scope | ) |
Unblock all waiters.
[in,out] | scope | the mutex scope that protects this conditional variable |
You should set the real condition variable itself after locking the mutex before calling this method to avoid lost signals.
Definition at line 123 of file shared_cond.cpp.
References ASSERT_ND, foedus::assorted::memory_fence_acq_rel(), foedus::assorted::spinlock_yield(), foedus::soc::ugly_atomic_dec(), foedus::soc::ugly_atomic_inc(), and foedus::soc::SharedMutexScope::unlock().
void foedus::soc::SharedCond::broadcast_nolock | ( | ) |
Unblock all waiters without a mutex held by the signaller.
You should set the real condition variable itself after locking the mutex, AND release it before calling this method. This method does not assume a mutex, thus a lost signal is possible.
Definition at line 141 of file shared_cond.cpp.
References ASSERT_ND, foedus::soc::ugly_atomic_dec(), and foedus::soc::ugly_atomic_inc().
|
inline |
A non-synchronized method to tell seemingly whether there is a waiter or not.
The caller is responsible for using this method with appropriate fences, retries, etc.
Definition at line 134 of file shared_cond.hpp.
|
inline |
Returns the mutex that protects this condition variable.
You must lock this mutex BEFORE you call wait/notify/etc in this class along with checking the real boolean condition itself. Otherwise, you will get lost signals. This is why the methods above receive SharedMutexScope as parameter.
Definition at line 128 of file shared_cond.hpp.
void foedus::soc::SharedCond::initialize | ( | ) |
Definition at line 33 of file shared_cond.cpp.
References ASSERT_ND, foedus::soc::SharedMutex::initialize(), and uninitialize().
Referenced by SharedCond().
|
inline |
Definition at line 50 of file shared_cond.hpp.
|
delete |
void foedus::soc::SharedCond::signal | ( | SharedMutexScope * | scope | ) |
Unblock one waiter.
[in,out] | scope | the mutex scope that protects this conditional variable |
You should set the real condition variable itself after locking the mutex before calling this method to avoid lost signals.
Definition at line 149 of file shared_cond.cpp.
References ASSERT_ND, foedus::soc::ugly_atomic_dec(), foedus::soc::ugly_atomic_inc(), and foedus::soc::SharedMutexScope::unlock().
bool foedus::soc::SharedCond::timedwait | ( | SharedMutexScope * | scope, |
uint64_t | timeout_nanosec | ||
) |
Wait for the event up to the given timeout.
[in,out] | scope | the mutex scope that protects this conditional variable |
[in] | timeout_nanosec | timeout in nanoseconds |
This method does NOT rule out spurrious wakeup as described above.
Definition at line 103 of file shared_cond.cpp.
References ASSERT_ND, CXX11_NULLPTR, foedus::soc::SharedMutex::get_raw_mutex(), foedus::soc::ugly_atomic_dec(), and foedus::soc::ugly_atomic_inc().
void foedus::soc::SharedCond::uninitialize | ( | ) |
Definition at line 50 of file shared_cond.cpp.
References ASSERT_ND, foedus::assorted::memory_fence_acquire(), foedus::assorted::spinlock_yield(), and foedus::soc::SharedMutex::uninitialize().
Referenced by initialize(), and ~SharedCond().
void foedus::soc::SharedCond::wait | ( | SharedMutexScope * | scope | ) |
Unconditionally wait for the event.
[in,out] | scope | the mutex scope that protects this conditional variable |
This method does NOT rule out spurrious wakeup. We could receive a lambda to check the condition, but this class should be C++11-free. So, the caller should do the loop herself if she doesn't want a spurrious wakeup. Instead, you can easily avoid lost signals by checking the condition after locking the mutex before calling this method.
Definition at line 90 of file shared_cond.cpp.
References ASSERT_ND, foedus::soc::SharedMutex::get_raw_mutex(), foedus::soc::ugly_atomic_dec(), and foedus::soc::ugly_atomic_inc().