nidas
v1.2-1520
|
A wrapper class for a Posix condition variable. More...
#include <ThreadSupport.h>
Public Member Functions | |
Cond () throw () | |
Construct a POSIX condition variable, with default attributes. More... | |
Cond (const Cond &x) throw () | |
Copy constructor. More... | |
~Cond () | |
Destruct a Cond. More... | |
void | lock () throw (Exception) |
Lock the mutex associated with the condition variable. More... | |
void | unlock () throw (Exception) |
Unlock the mutex associated with the condition variable. More... | |
void | signal () throw (Exception) |
Unblock at least one thread waiting on the condition variable. More... | |
void | broadcast () |
Restart all threads waiting on the condition variable. More... | |
void | wait () throw (Exception) |
Wait on the condition variable. More... | |
Private Member Functions | |
Cond & | operator= (const Cond &) |
No assignment allowed. More... | |
Private Attributes | |
pthread_cond_t | _p_cond |
Mutex | _mutex |
A wrapper class for a Posix condition variable.
Cond::Cond | ( | ) | ||
throw | ( | |||
) |
Construct a POSIX condition variable, with default attributes.
See man page for pthread_cond_init.
Cond::Cond | ( | const Cond & | x | ) | |
throw | ( | ||||
) |
Copy constructor.
Creates new unlocked condition variable and mutex.
Cond::~Cond | ( | ) |
Destruct a Cond.
See man page for pthread_cond_destroy. Cond must not be waited on by any thread, otherwise std::terminate() is called.
References _p_cond, CLOG, and nidas::util::Exception::what().
|
inline |
Restart all threads waiting on the condition variable.
References _p_cond.
Referenced by PacketReader::loop(), nidas::core::SampleBuffer::run(), nidas::core::SampleSorter::run(), and nidas::util::Multisync::sync().
|
inline |
Lock the mutex associated with the condition variable.
Here is an example (lifted from the pthread_cond_init man page): of two threads sharing variables x and y. One thread waits for a signal that x is greater than y:
Another thread manipulates x and y and signals when x > y:
References _mutex, and nidas::util::Mutex::lock().
Referenced by nidas::util::McSocket< SocketT >::accept(), nidas::core::SampleOutputRequestThread::addConnectRequest(), nidas::core::SampleOutputRequestThread::addDeleteRequest(), nidas::core::SampleOutputRequestThread::clear(), nidas::util::McSocket< SocketT >::connect(), nidas::dynld::raf::SyncRecordReader::endOfStream(), nidas::core::SampleSorter::flush(), nidas::core::SampleBuffer::heapDecrement(), nidas::core::SampleSorter::heapDecrement(), nidas::core::SensorOpener::interrupt(), nidas::core::SampleBuffer::interrupt(), nidas::core::SampleSorter::interrupt(), PacketReader::loop(), nidas::dynld::raf::SyncRecordReader::nextSample(), nidas::util::McSocket< SocketT >::offer(), nidas::core::SensorOpener::openSensor(), nidas::core::SensorOpener::reopenSensor(), nidas::core::SampleOutputRequestThread::run(), nidas::core::SensorOpener::run(), nidas::core::SampleBuffer::run(), nidas::core::SampleSorter::run(), WriterThread::run(), PacketReader::~PacketReader(), and nidas::dynld::raf::SyncRecordReader::~SyncRecordReader().
|
inline |
Unblock at least one thread waiting on the condition variable.
References _p_cond.
Referenced by nidas::core::SampleOutputRequestThread::addConnectRequest(), nidas::core::SampleOutputRequestThread::addDeleteRequest(), nidas::dynld::raf::SyncRecordReader::endOfStream(), nidas::core::SampleSorter::flush(), nidas::core::SampleBuffer::heapDecrement(), nidas::core::SampleSorter::heapDecrement(), nidas::core::SampleOutputRequestThread::interrupt(), nidas::core::SensorOpener::interrupt(), nidas::core::SampleBuffer::interrupt(), nidas::core::SampleSorter::interrupt(), nidas::dynld::raf::SyncRecordReader::nextSample(), nidas::util::McSocket< SocketT >::offer(), nidas::core::SensorOpener::openSensor(), nidas::core::SensorOpener::reopenSensor(), and nidas::core::SampleSorter::run().
|
inline |
Unlock the mutex associated with the condition variable.
References _mutex, and nidas::util::Mutex::unlock().
Referenced by nidas::util::McSocket< SocketT >::accept(), nidas::core::SampleOutputRequestThread::addConnectRequest(), nidas::core::SampleOutputRequestThread::addDeleteRequest(), nidas::core::SampleOutputRequestThread::clear(), nidas::util::McSocket< SocketT >::connect(), nidas::dynld::raf::SyncRecordReader::endOfStream(), nidas::core::SampleSorter::flush(), nidas::core::SampleBuffer::heapDecrement(), nidas::core::SampleSorter::heapDecrement(), nidas::core::SensorOpener::interrupt(), nidas::core::SampleBuffer::interrupt(), nidas::core::SampleSorter::interrupt(), PacketReader::loop(), nidas::dynld::raf::SyncRecordReader::nextSample(), nidas::util::McSocket< SocketT >::offer(), nidas::core::SensorOpener::openSensor(), nidas::core::SensorOpener::reopenSensor(), nidas::core::SampleOutputRequestThread::run(), nidas::core::SensorOpener::run(), nidas::core::SampleBuffer::run(), nidas::core::SampleSorter::run(), WriterThread::run(), PacketReader::~PacketReader(), and nidas::dynld::raf::SyncRecordReader::~SyncRecordReader().
void Cond::wait | ( | ) | ||
throw | ( | Exception | ||
) |
Wait on the condition variable.
References _mutex, _p_cond, and nidas::util::Mutex::ptr().
Referenced by nidas::util::McSocket< SocketT >::accept(), nidas::util::McSocket< SocketT >::connect(), nidas::core::SampleSorter::flush(), nidas::dynld::raf::SyncRecordReader::nextSample(), nidas::core::SampleOutputRequestThread::run(), nidas::core::SensorOpener::run(), nidas::core::SampleBuffer::run(), nidas::core::SampleSorter::run(), WriterThread::run(), and nidas::util::Multisync::sync().
|
private |
Referenced by broadcast(), signal(), wait(), and ~Cond().