Public Member Functions | Private Attributes
Condition Class Reference

#include <Condition.h>

List of all members.

Public Member Functions

void broadcast ()
 Condition ()
void signal ()
void wait (Mutex &mutex)
void wait (Mutex &mutex, unsigned int maxTime)
virtual ~Condition ()

Private Attributes

TConditionm_Condition
bool m_SignalArrived
Mutex m_SignalArrivedMutex

Detailed Description

A synchronization object for one-to-one or one-to-many control events.

The Condition class provides a synchonization object for one-to-one and one-to-many control events. Using this class, it is possible to pause the execution of a thread until it gets a signal from another thread to continue. This signal can be sent to only a single thread (one-to-one event) via signal or to all threads waiting for the condition object (one-to-many) via broadcast.

Note that sometimes signals are issued by the operating system and not only by other threads. So the criterion you are waiting for may not be satisfied. However, this can be handled using a loop:

    Condition condition;
    bool criterion;
    Mutex mutex;
    mutex.lock();
    ...
    while( !criterion){
      condition.wait(mutex);
    }
    ...
    mutex.unlock();

The signaling thread should use code like the following:

    criterion = true;
    condition.signal();   // or "condition.broadcast()"

Definition at line 53 of file Condition.h.


Constructor & Destructor Documentation

Default constructor. Creates a new platform-dependent condition object.

Definition at line 22 of file Condition.cpp.

Condition::~Condition ( ) [virtual]

Destructor. Destroys the instance and releases all associated system resources.

Definition at line 30 of file Condition.cpp.


Member Function Documentation

Issue a signal and wake up all threads waiting for this condition. This is useful for a one-to-many control event.

Definition at line 93 of file Condition.cpp.

Issue a signal and wake up a single thread waiting for this condition. This is useful for a one-to-one control event.

Definition at line 84 of file Condition.cpp.

void Condition::wait ( Mutex mutex)

Wait for a signal. Pauses the thread, unlock's the given mutex and waits for a signal before the execution is continued.

Parameters:
mutexMutex that is unlocked until the thread wakes up again

Definition at line 37 of file Condition.cpp.

void Condition::wait ( Mutex mutex,
unsigned int  maxTime 
)

Wait for a signal until a given maximum time has passed

Parameters:
maxTimeMaximal wait time [ms]
See also:
wait( Mutex& )

Definition at line 56 of file Condition.cpp.


Member Data Documentation

Platform-dependent condition representation.

Definition at line 103 of file Condition.h.

This variable is set to true when a signal arrives. It serves as a reminder in the case that a signal arrives before a process starts waiting on it. After every wait call this variable will be set to false.

Definition at line 109 of file Condition.h.

This mutex is needed for locking the condition while the variable m_SignalArrived is modified and read by another process. Without this mutex it would be possible that signals arrive before a process starts waiting on them.

Definition at line 116 of file Condition.h.


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


robbie_architecture
Author(s): Viktor Seib
autogenerated on Mon Oct 6 2014 02:53:09