OpenWalnut
1.4.0
|
Implements a WCondition, but can be fired only ONCE. More...
#include <WConditionOneShot.h>
Public Member Functions | |
WConditionOneShot () | |
Default constructor. | |
virtual | ~WConditionOneShot () |
Destructor. | |
virtual void | wait () const |
Wait for the condition. | |
virtual void | notify () |
Notifies all waiting threads. | |
Protected Attributes | |
boost::unique_lock < boost::shared_mutex > | m_lock |
Locked as long the condition was not fired. | |
Friends | |
class | WConditionOneShot_test |
Implements a WCondition, but can be fired only ONCE.
This is useful if you want to have a thread waiting for a condition but you can not assure that the thread already waits when you set the condition. This would cause the thread to wait endlessly because he does not know that you already fired it. Implementation is simple. The constructor uses a unique lock (write lock) on a mutex. All waiting threads try to get a read lock which is not possible as long it is write-locked. The notify method releases the write lock and all waiting threads can continue.
Definition at line 40 of file WConditionOneShot.h.
Default constructor.
Definition at line 27 of file WConditionOneShot.cpp.
References m_lock, and WCondition::m_mutex.
WConditionOneShot::~WConditionOneShot | ( | ) | [virtual] |
void WConditionOneShot::notify | ( | ) | [virtual] |
Notifies all waiting threads.
Reimplemented from WCondition.
Definition at line 54 of file WConditionOneShot.cpp.
References m_lock.
Referenced by WGraphicsEngine::finalizeStartup(), WGraphicsEngine::notifyStop(), WConditionOneShotTest::testWaitNotify(), and WKernel::threadMain().
void WConditionOneShot::wait | ( | ) | const [virtual] |
Wait for the condition.
Sets the calling thread asleep.
Reimplemented from WCondition.
Definition at line 47 of file WConditionOneShot.cpp.
References WCondition::m_mutex.
Referenced by WConditionOneShotTest::testWaitNotify(), WGraphicsEngine::threadMain(), and WGraphicsEngine::waitForFinalize().
boost::unique_lock<boost::shared_mutex> WConditionOneShot::m_lock [protected] |
Locked as long the condition was not fired.
Definition at line 68 of file WConditionOneShot.h.
Referenced by notify(), WConditionOneShot(), and ~WConditionOneShot().