#include <cascade/interthread/CascadeMonitor.h>
Inheritance diagram for CascadeMonitor:
Public Member Functions | |
CascadeMonitor () | |
virtual | ~CascadeMonitor () |
void | Enter () |
void | Exit () |
void | Notify () |
void | Broadcast () |
bool | WaitForNotification (u32 nTimeoutMilliseconds=0) |
CascadeMonitor provides a thread-safe monitor that provides mutex-like protection with notification condition variables.
|
the default constructor - lightweight This default constructor is lightweight. |
|
destructor The destructor. |
|
broadcasts the monitor's condition Broadcast() operates as Notify() does but wakes up all threads (not just one) that are waiting for notification on this monitor. |
|
enters the monitor Call Enter() to enter the monitor. Once you have entered the monitor, you own access to the monitored data. (It's like entering a critical section). You MUST enter the monitor prior to calling WaitForNotification() or your wait will be a 'naked' wait.
|
|
exits the monitor Call Exit() to exit the monitor. Once you call Exit() other threads may Enter() the monitor.
|
|
notifies the monitor's condition Call Notify() to wake up one (1) thread that is waiting for notification on this monitor. There are two ways to call Notify() - with the monitor entered, or not. The latter is referred to as a naked notify and is used when the monitor is not protecting access to external data. The more common case is the non-naked notify: monitor.Enter(); someMonitoredDataValue = 3; // fiddle with the monitored data monitor.Notify(); // notify that we've appropriately fiddled with the monitored data monitor.Exit(); // notified thread will wake up (and re-enter the monitor) when Exit() is called.
|
|
waits for a monitor's condition to be notified or broadcast by another thread WaitForNotification() causes the calling thread to wait until another thread notifies the monitor (with either Broadcast() or Notify()), or until nTimeoutMilliseconds milliseconds have expired (0 means infinite). If the function returns true, the monitor was notified. If the function returns false, the outcome was a timeout. Note that like Notify() and B%roadcast(), Waits are naked-Waits if the monitor is not entered when WaitForNotification() is called. Naked waits are almost never used, and are only useful when there is no monitored data or when there is no interest in the monitored data. The more-usual case is the non-naked Wait: monitor.Enter(); if (someMonitoredDataValue != 3) // check to see if I should wait monitor.WaitForNotification(); // waiting will exit the monitor for the duration of the wait ASSERT(someMonitoredDataValue == 3);// after waiting I have automatically re-entered the monitor monitor.Exit(); // I'm still in the monitor, so must exit
|