Condition Class Reference

#include <Pt/System/Condition.h>

Signal and wait synchronisation primitive. More...

Inherits NonCopyable.

Public Member Functions

 Condition ()
 Default Constructor.
 ~Condition ()
 Destructor.
void wait (Mutex &mtx)
 Wait until the condition is signaled.
void wait (MutexLock &m)
 Wait until condition becomes signaled.
bool wait (Mutex &mtx, unsigned int ms)
 Wait until the condition is signaled or ms elapses.
bool wait (MutexLock &m, unsigned int ms)
 Wait until condition becomes signalled.
void signal ()
 Unblock a single blocked thread.
void broadcast ()
 Unblock all blocked threads.

Detailed Description

Condition waits while a Mutex is held. wait() unlocks that mutex, suspends the caller, and relocks when the wait ends. A timed wait returns false on timeout. signal() wakes one waiter. broadcast() wakes all.

Member Function Documentation

◆ wait() [1/3]

void wait ( MutexLock & m)

Causes the caller to be suspended until the condition will be signaled. The given mutex will be unlocked before the caller is suspended.

◆ wait() [2/3]

bool wait ( Mutex & mtx,
unsigned int ms )

Returns false if the wait timed out.

◆ wait() [3/3]

bool wait ( MutexLock & m,
unsigned int ms )

Causes the caller to be suspended until the condition will be signaled. The given mutex will be unlocked before the caller is suspended. The suspension takes at maximum ms milliseconds. Returns true if successful, false if a timeout occurred.