OpenWalnut  1.4.0
Public Member Functions | Protected Attributes | Friends | List of all members
WConditionOneShot Class Reference

Implements a WCondition, but can be fired only ONCE. More...

#include <WConditionOneShot.h>

+ Inheritance diagram for WConditionOneShot:

Public Member Functions

 WConditionOneShot ()
 Default constructor.
virtual ~WConditionOneShot ()
 Destructor.
virtual void wait () const
 Wait for the condition.
virtual void notify ()
 Notifies all waiting threads.
- Public Member Functions inherited from WCondition
 WCondition ()
 Default constructor.
virtual ~WCondition ()
 Destructor.
boost::signals2::connection subscribeSignal (t_ConditionNotifierType notifier) const
 Subscribes a specified function to be notified on condition change.

Protected Attributes

boost::unique_lock
< boost::shared_mutex > 
m_lock
 Locked as long the condition was not fired.
- Protected Attributes inherited from WCondition
t_ConditionSignalType signal_ConditionFired
 Signal getting fired whenever the condition fires.
boost::condition_variable_any m_condition
 The condition.
boost::shared_mutex m_mutex
 The mutex used for the condition.

Friends

class WConditionOneShot_test

Additional Inherited Members

- Public Types inherited from WCondition
typedef boost::shared_ptr
< WCondition
SPtr
 Shared pointer type for WCondition.
typedef boost::shared_ptr
< const WCondition
ConstSPtr
 Const shared pointer type for WCondition.
typedef boost::function0< void > t_ConditionNotifierType
 Type used for signalling condition changes.
- Protected Types inherited from WCondition
typedef
boost::signals2::signal< void(void)> 
t_ConditionSignalType
 Type used for condition notification.

Detailed Description

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.

Constructor & Destructor Documentation

WConditionOneShot::WConditionOneShot ( )

Default constructor.

Definition at line 27 of file WConditionOneShot.cpp.

References m_lock, and WCondition::m_mutex.

WConditionOneShot::~WConditionOneShot ( )
virtual

Destructor.

Definition at line 34 of file WConditionOneShot.cpp.

References m_lock.

Member Function Documentation

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().

Member Data Documentation

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().


The documentation for this class was generated from the following files: