Deskflow 1.22.0.197
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
CondVarBase Class Reference

Generic condition variable. More...

#include <CondVar.h>

Inheritance diagram for CondVarBase:

Public Member Functions

 CondVarBase (Mutex *mutex)
 ~CondVarBase ()
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 (Stopwatch &timer, double timeout) const
 Wait on the condition variable.
MutexgetMutex () 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.

Constructor & Destructor Documentation

◆ CondVarBase()

CondVarBase::CondVarBase ( Mutex * mutex)
explicit

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

◆ ~CondVarBase()

CondVarBase::~CondVarBase ( )

Member Function Documentation

◆ broadcast()

void CondVarBase::broadcast ( )

Signal the condition variable.

Wake up all waiting threads, if any.

◆ getMutex()

Mutex * CondVarBase::getMutex ( ) const

Get the mutex.

Get the mutex passed to the c'tor.

◆ lock()

void CondVarBase::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.

◆ signal()

void CondVarBase::signal ( )

Signal the condition variable.

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

◆ unlock()

void CondVarBase::unlock ( ) const

Unlock the condition variable's mutex.

◆ wait() [1/2]

bool CondVarBase::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)

◆ wait() [2/2]

bool CondVarBase::wait ( Stopwatch & timer,
double timeout ) const

Wait on the condition variable.

Same as wait(double) but use timer to compare against timeout. 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)


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