OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
WConditionSet Class Reference

Class allowing multiple conditions to be used for one waiting cycle. More...

#include <WConditionSet.h>

+ Inheritance diagram for WConditionSet:

Public Member Functions

 WConditionSet ()
 Default constructor.
virtual ~WConditionSet ()
 Destructor.
virtual void add (boost::shared_ptr< WCondition > condition)
 Adds another condition to the set of conditions to wait for.
virtual void remove (boost::shared_ptr< WCondition > condition)
 Removes the specified condition.
virtual void wait () const
 Wait for the condition.
virtual void reset () const
 Resets the internal fire state.
void setResetable (bool resetable=true, bool autoReset=true)
 Sets the resetable flag.
bool isResetable ()
 Returns whether the condition set acts like a one shot condition.
- Public Member Functions inherited from WCondition
 WCondition ()
 Default constructor.
virtual ~WCondition ()
 Destructor.
virtual void notify ()
 Notifies all waiting threads.
boost::signals2::connection subscribeSignal (t_ConditionNotifierType notifier)
 Subscribes a specified function to be notified on condition change.

Protected Types

typedef std::map
< boost::shared_ptr
< WCondition >
, boost::signals2::connection > 
ConditionConnectionMap
 We need to keep track of the connections a condition has made since boost::function objects do not provide a == operator and can therefore not easily be removed from a signals by signal.desconnect( functor ).
typedef std::pair
< boost::shared_ptr
< WCondition >
, boost::signals2::connection > 
ConditionConnectionPair
 Each condition has a connection.
- Protected Types inherited from WCondition
typedef
boost::signals2::signal< void(void)> 
t_ConditionSignalType
 Type used for condition notification.

Protected Member Functions

virtual void conditionFired ()
 Notifier function getting notified whenever a condition got fired.

Protected Attributes

bool m_resetable
 Flag denoting whether the condition set should act like a one shot condition.
bool m_autoReset
 Flag which shows whether the wait() call should reset the state m_fired when it returns.
ConditionConnectionMap m_conditionSet
 Set of conditions to be waited for.
boost::shared_mutex m_conditionSetLock
 Lock used for thread-safe writing to the condition set.
bool m_fired
 Flag denoting whether one condition fired in the past.
WCondition::t_ConditionNotifierType m_notifier
 The notifier which gets called by all conditions if they fire.
- 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 WConditionSetTest

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.

Detailed Description

Class allowing multiple conditions to be used for one waiting cycle.

Since wait() can not be used for waiting on multiple conditions, this class can encapsulate multiple conditions and offer a wait() command to wait for one of them to change its state. Please not that this class can also be used as condition.

Definition at line 42 of file WConditionSet.h.

Member Typedef Documentation

typedef std::map< boost::shared_ptr< WCondition >, boost::signals2::connection > WConditionSet::ConditionConnectionMap
protected

We need to keep track of the connections a condition has made since boost::function objects do not provide a == operator and can therefore not easily be removed from a signals by signal.desconnect( functor ).

Definition at line 119 of file WConditionSet.h.

typedef std::pair< boost::shared_ptr< WCondition >, boost::signals2::connection > WConditionSet::ConditionConnectionPair
protected

Each condition has a connection.

Definition at line 129 of file WConditionSet.h.

Constructor & Destructor Documentation

WConditionSet::WConditionSet ( )

Default constructor.

Definition at line 27 of file WConditionSet.cpp.

WConditionSet::~WConditionSet ( )
virtual

Destructor.

Definition at line 36 of file WConditionSet.cpp.

References m_conditionSet, and m_conditionSetLock.

Member Function Documentation

void WConditionSet::add ( boost::shared_ptr< WCondition condition)
virtual

Adds another condition to the set of conditions to wait for.

Note that, whenever someone is waiting for this WConditionSet, the newly added one is also directly included into the wait() call.

Parameters
conditionthe condition to add.

Definition at line 52 of file WConditionSet.cpp.

References m_conditionSet, m_conditionSetLock, and m_notifier.

Referenced by WConditionSetTest::testAddRemove(), WConditionSetTest::testWait(), WConditionSetTest::testWaitResetable(), and WModule::WModule().

void WConditionSet::conditionFired ( )
protectedvirtual

Notifier function getting notified whenever a condition got fired.

Definition at line 83 of file WConditionSet.cpp.

References m_fired, and WCondition::notify().

bool WConditionSet::isResetable ( )

Returns whether the condition set acts like a one shot condition.

Returns
true if the fire state is delayed and can be reseted.

Definition at line 113 of file WConditionSet.cpp.

References m_resetable.

void WConditionSet::remove ( boost::shared_ptr< WCondition condition)
virtual

Removes the specified condition.

As add() this immediately takes effect on running wait() calls.

Parameters
conditionthe condition to remove

Definition at line 67 of file WConditionSet.cpp.

References m_conditionSet, and m_conditionSetLock.

Referenced by WConditionSetTest::testAddRemove(), and WConditionSetTest::testWait().

void WConditionSet::reset ( ) const
virtual

Resets the internal fire state.

This does nothing if !isResetable().

Definition at line 102 of file WConditionSet.cpp.

References m_fired.

Referenced by WConditionSetTest::testResetOnNotResetable(), WConditionSetTest::testWait(), and wait().

void WConditionSet::setResetable ( bool  resetable = true,
bool  autoReset = true 
)

Sets the resetable flag.

This causes the condition set to act like a WConditionOneShot. There are several implications to this you should consider when using the condition set as a resetable. If one condition in the condition set fires, a subsequent call to wait() will immediately return until a reset() call has been done. If you share one condition set among several threads, you should consider, that one thread can reset the condition set before the other thread had a chance to call wait() which causes the other thread to wait until the next condition in the set fires.

Parameters
resetabletrue if the fire state should be delayed and can be reseted.
autoResettrue if the state should be reset whenever a wait call is called and continues.This is especially useful if a condition set is used only by one thread, so there is no need to call reset() explicitly.

Definition at line 107 of file WConditionSet.cpp.

References m_autoReset, and m_resetable.

Referenced by WConditionSetTest::testResetOnNotResetable(), WConditionSetTest::testWait(), WConditionSetTest::testWaitResetable(), and WModule::WModule().

void WConditionSet::wait ( ) const
virtual

Wait for the condition.

Sets the calling thread asleep. If the condition set is resetable, this will return immediately when a condition in the set fired in the past and there has been no reset() call until now.

Reimplemented from WCondition.

Definition at line 89 of file WConditionSet.cpp.

References m_autoReset, m_fired, m_resetable, and reset().

Referenced by WConditionSetTest::testWait(), and WConditionSetTest::testWaitResetable().

Member Data Documentation

bool WConditionSet::m_autoReset
protected

Flag which shows whether the wait() call should reset the state m_fired when it returns.

Definition at line 113 of file WConditionSet.h.

Referenced by setResetable(), and wait().

ConditionConnectionMap WConditionSet::m_conditionSet
protected

Set of conditions to be waited for.

Definition at line 124 of file WConditionSet.h.

Referenced by add(), remove(), WConditionSetTest::testAddRemove(), and ~WConditionSet().

boost::shared_mutex WConditionSet::m_conditionSetLock
protected

Lock used for thread-safe writing to the condition set.

Definition at line 134 of file WConditionSet.h.

Referenced by add(), remove(), and ~WConditionSet().

bool WConditionSet::m_fired
mutableprotected

Flag denoting whether one condition fired in the past.

Just useful when m_resetable is true.

Definition at line 144 of file WConditionSet.h.

Referenced by conditionFired(), reset(), WConditionSetTest::testWait(), WConditionSetTest::testWaitResetable(), and wait().

WCondition::t_ConditionNotifierType WConditionSet::m_notifier
protected

The notifier which gets called by all conditions if they fire.

Definition at line 149 of file WConditionSet.h.

Referenced by add().

bool WConditionSet::m_resetable
protected

Flag denoting whether the condition set should act like a one shot condition.

Definition at line 108 of file WConditionSet.h.

Referenced by isResetable(), setResetable(), and wait().


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