OpenWalnut
1.4.0
|
Class allowing multiple conditions to be used for one waiting cycle. More...
#include <WConditionSet.h>
Public Types | |
typedef boost::shared_ptr < WConditionSet > | SPtr |
Shared pointer to instance of this class. | |
typedef boost::shared_ptr < const WConditionSet > | ConstSPtr |
Shared pointer to const instance of this class. | |
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. | |
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 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. | |
Friends | |
class | WConditionSetTest |
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.
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 127 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 137 of file WConditionSet.h.
typedef boost::shared_ptr< const WConditionSet > WConditionSet::ConstSPtr |
Shared pointer to const instance of this class.
Reimplemented from WCondition.
Definition at line 54 of file WConditionSet.h.
typedef boost::shared_ptr< WConditionSet > WConditionSet::SPtr |
Shared pointer to instance of this class.
Reimplemented from WCondition.
Definition at line 49 of file WConditionSet.h.
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.
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.
condition | the 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 | ( | ) | [protected, virtual] |
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.
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.
condition | the 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.
resetable | true if the fire state should be delayed and can be reseted. |
autoReset | true 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().
bool WConditionSet::m_autoReset [protected] |
Flag which shows whether the wait() call should reset the state m_fired when it returns.
Definition at line 121 of file WConditionSet.h.
Referenced by setResetable(), and wait().
ConditionConnectionMap WConditionSet::m_conditionSet [protected] |
Set of conditions to be waited for.
Definition at line 132 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 142 of file WConditionSet.h.
Referenced by add(), remove(), and ~WConditionSet().
bool WConditionSet::m_fired [mutable, protected] |
Flag denoting whether one condition fired in the past.
Just useful when m_resetable is true.
Definition at line 152 of file WConditionSet.h.
Referenced by conditionFired(), reset(), WConditionSetTest::testWait(), WConditionSetTest::testWaitResetable(), and wait().
The notifier which gets called by all conditions if they fire.
Definition at line 157 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 116 of file WConditionSet.h.
Referenced by isResetable(), setResetable(), and wait().