OpenDaVINCI  4.15.3
odcore::base::Condition Class Reference

#include <Condition.h>

Inheritance diagram for odcore::base::Condition:
Inheritance graph

Public Member Functions

 Condition ()
virtual ~Condition ()
void waitOnSignal ()
bool waitOnSignalWithTimeout (const unsigned long &ms)
void wakeOne ()
void wakeAll ()

Protected Member Functions

virtual void lock ()
virtual bool tryLock ()
virtual void unlock ()


class Lock

Detailed Description

This class implements a condition for waiting on signals:

Thread 1: [...]

Lock l(c);
if (sleep) {
c.waitOnSignal(); // Now, the execution of the current thread is suspended.

Thread 2: [...]

Condition &c = thread1.getCondition();
Lock l(c);
sleep = false
c.wakeOne(); // Wake up sleeping thread 1.
// or:
Lock l(c);
sleep = false
c.wakeAll(); // Wake up all threads sleeping on this condition.

It is important that a condition is locked before waitOnSignal, wakeOne or wakeAll are called. Otherwise you will get an assertion error. The lock is released before the condition is put asleep or woken up and locked again before the mehtod returns. This way, sleep can be modified thread-safe by different threads.

Constructor & Destructor Documentation

odcore::base::Condition::Condition ( )
odcore::base::Condition::~Condition ( )

Member Function Documentation

void odcore::base::Condition::lock ( )

This method locks the condition's mutex.

Reimplemented from odcore::base::Mutex.

bool odcore::base::Condition::tryLock ( )

This method tries to lock the condition's mutex.

true, if the mutex could be locked.

Reimplemented from odcore::base::Mutex.

void odcore::base::Condition::unlock ( )

This method unlocks the condition's mutex.

Reimplemented from odcore::base::Mutex.

void odcore::base::Condition::waitOnSignal ( )
bool odcore::base::Condition::waitOnSignalWithTimeout ( const unsigned long &  ms)

This methods suspends the execution of the current thread with a timeout

TRUE if condition awakes, FALSE if timeout occurs

Referenced by odcore::dmcp::connection::ModuleConnection::pulse_ack(), odcore::dmcp::connection::ModuleConnection::pulse_ack_containers(), and odcore::dmcp::discoverer::Client::waitForResponse().

void odcore::base::Condition::wakeOne ( )

This method awakes only one sleeping thread.

Friends And Related Function Documentation

friend class Lock