CCondVarBase Class Reference

Generic condition variable. More...

#include <CCondVar.h>

Inherited by CCondVar< T >, and CCondVar< bool >.

Inheritance diagram for CCondVarBase:

Inheritance graph
[legend]
Collaboration diagram for CCondVarBase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CCondVarBase (CMutex *mutex)
 ~CCondVarBase ()
manipulators
void lock () const
 Lock the condition variable's mutex.
void unlock () const
 Unlock the condition variable's mutex.
void signal ()
 Signal the condition variable.
void broadcast ()
 Signal the condition variable.
accessors
bool wait (double timeout=-1.0) const
 Wait on the condition variable.
bool wait (CStopwatch &timer, double timeout) const
 Wait on the condition variable.
CMutexgetMutex () const
 Get the mutex.

Detailed Description

Generic condition variable.

This class provides functionality common to all condition variables but doesn't provide the actual variable storage. A condition variable is a multiprocessing primitive that can be waited on. Every condition variable has an associated mutex.

Definition at line 30 of file CCondVar.h.


Constructor & Destructor Documentation

CCondVarBase::CCondVarBase ( CMutex mutex  ) 

mutex must not be NULL. All condition variables have an associated mutex. The mutex needn't be unique to one condition variable.

Definition at line 23 of file CCondVar.cpp.


Member Function Documentation

void CCondVarBase::broadcast (  ) 

Signal the condition variable.

Wake up all waiting threads, if any.

Definition at line 54 of file CCondVar.cpp.

CMutex * CCondVarBase::getMutex (  )  const

Get the mutex.

Get the mutex passed to the c'tor.

Definition at line 78 of file CCondVar.cpp.

void CCondVarBase::lock (  )  const

Lock the condition variable's mutex.

Lock the condition variable's mutex. The condition variable should be locked before reading or writing it. It must be locked for a call to wait(). Locks are not recursive; locking a locked mutex will deadlock the thread.

Definition at line 36 of file CCondVar.cpp.

References CMutex::lock().

void CCondVarBase::signal (  ) 

Signal the condition variable.

Wake up one waiting thread, if there are any. Which thread gets woken is undefined.

Definition at line 48 of file CCondVar.cpp.

bool CCondVarBase::wait ( CStopwatch timer,
double  timeout 
) const

Wait on the condition variable.

Same as wait(double) but use timer to compare against . Since clients normally wait on condition variables in a loop, clients can use this to avoid recalculating timeout on each iteration. Passing a stopwatch with a negative timeout is pointless (it will never time out) but permitted.

(cancellation point)

Definition at line 60 of file CCondVar.cpp.

References CStopwatch::getTime(), and wait().

bool CCondVarBase::wait ( double  timeout = -1.0  )  const

Wait on the condition variable.

Wait on the condition variable. If timeout < 0 then wait until signalled, otherwise up to timeout seconds or until signalled, whichever comes first. Returns true if the object was signalled during the wait, false otherwise.

The proper way to wait for a condition is:

    cv.lock();
    while (cv-expr) {
        cv.wait();
    }
    cv.unlock();
where cv-expr involves the value of cv and is false when the condition is satisfied.

(cancellation point)

Definition at line 72 of file CCondVar.cpp.

References CMutex::m_mutex.

Referenced by CTCPSocket::flush(), and wait().


The documentation for this class was generated from the following files:
Generated on Fri Nov 6 00:18:58 2009 for synergy-plus by  doxygen 1.4.7