CrystalSpace

Public API Reference

CS::Threading::Condition Class Reference

Condition variable. More...

#include <csutil/threading/condition.h>

Inheritance diagram for CS::Threading::Condition:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 Condition ()
void NotifyAll ()
 Notify and wake up all threads currently waiting for the condition.
void NotifyOne ()
 Notify and wake up one thread waiting for the condition.
template<typename LockType>
bool Wait (LockType &lock, csTicks timeout=0)
 Wait for some change of condition.


Detailed Description

Condition variable.

A condition variable is a synchronization primitive used to have threads wait for a shared state variable to attain a given value.

Definition at line 43 of file condition.h.


Member Function Documentation

void CS::Threading::Condition::NotifyAll (  )  [inline]

Notify and wake up all threads currently waiting for the condition.

The order different threads get woke up is indeterminate.

Definition at line 63 of file condition.h.

Referenced by CS::SndSys::Queue< CS::SndSys::SndSysBasicStream::StreamNotificationEvent >::Clear().

void CS::Threading::Condition::NotifyOne (  )  [inline]

Notify and wake up one thread waiting for the condition.

Definition at line 54 of file condition.h.

Referenced by CS::SndSys::Queue< CS::SndSys::SndSysBasicStream::StreamNotificationEvent >::QueueEntry().

template<typename LockType>
bool CS::Threading::Condition::Wait ( LockType &  lock,
csTicks  timeout = 0 
) [inline]

Wait for some change of condition.

Suspends the calling thread until some other thread invokes Notify() or NotifyAll() to notify a change of condition.

Parameters:
lock The mutex to associate with this condition. The caller must already hold a lock on the mutex before calling Wait(), and all threads waiting on the condition must be using the same mutex. The mutex must not be locked recursively within the same thread. When called, Wait() releases the caller's lock on the mutex and suspends the caller's thread. Upon return from Wait(), the caller's lock on the mutex is restored.
timeout Timeout in milliseconds for the wait. A value of 0 means infinite wait.
Returns:
true when the condition was changed, or false if the wait timed out.
Remarks:
The reason that the mutex must not be locked recursively is because the implicit unlock performed by Wait() must actually release the mutex in order for other threads to be able to satisfy the condition. With recursively locked mutexes, there is no guarantee that the one implicit unlock operation performed by Wait() will actually release the mutex since it might have been locked multiple times within the same thread.

Having to use a timed wait may indicate a code flaw. Try to avoid timed waits and instead fix your synchronization logic.

Definition at line 93 of file condition.h.

Referenced by CS::SndSys::Queue< CS::SndSys::SndSysBasicStream::StreamNotificationEvent >::DequeueEntry().


The documentation for this class was generated from the following file:
Generated for Crystal Space 1.2.1 by doxygen 1.5.3