Dv::Thread::Monitor Class Reference
#include <monitor.h>
List of all members.
Public Member Functions |
| Monitor (const std::string &name, unsigned int n_conditions=0, unsigned int min_debug_level=0, Debugable *debug_master=0) |
| Constructor.
|
virtual | ~Monitor () |
| Virtual destructor.
|
void | enter (const std::string *msg=0) |
| Enter the monitor.
|
void | exit (const std::string *msg=0) |
| Exit the monitor.
|
void | wait (unsigned int condition=0) |
| Unconditionally wait for a given condition.
|
bool | wait (unsigned int condition, time_t timeout) |
| Wait for a given condition or until timeout millisecs elapsed.
|
void | signal (unsigned int condition=0) const |
| Signal a given condition.
|
void | broadcast (unsigned int condition=0) const |
| Signal all threads waiting on this condition.
|
const std::string & | name () const |
pthread_t | owner () const |
bool | owned_by_self () const |
Private Member Functions |
void | check (const std::string &message) const |
| This functions throws a std::runtime_error if the current thread is not the current owner of the monitor.
|
void | check_cond (const std::string &msg, unsigned int n) const |
| This functions throws a runtime_error if n is not a valid condition of this monitor or if the current thread does not own the monitor.
|
| Monitor (const Monitor &) |
| No copy ctor.
|
Monitor & | operator= (const Monitor &) |
| No assignment operator.
|
Private Attributes |
std::string | name_ |
| Name of the monitor.
|
pthread_t | owner_ |
| Thread that currently owns the monitor.
|
pthread_mutex_t | mutex_ |
| Entry to the monitor is controlled by this mutex semaphore.
|
pthread_mutexattr_t | mutex_attributes_ |
| Attributes of mutex_.
|
unsigned int | n_conditions_ |
| Number of conditions of the monitor.
|
pthread_cond_t * | conditions_ |
| Array of n_conditions_ posix conditions of this monitor.
|
pthread_condattr_t | condition_attributes_ |
Detailed Description
- Examples:
-
test-pool.C.
Constructor & Destructor Documentation
Dv::Thread::Monitor::Monitor |
( |
const std::string & |
name, |
|
|
unsigned int |
n_conditions = 0 , |
|
|
unsigned int |
min_debug_level = 0 , |
|
|
Debugable * |
debug_master = 0 | |
|
) |
| | |
Constructor.
- Parameters:
-
| name | of this monitor. |
| n_conditions | number of conditions in this monitor. |
| min_debug_level | if a debug_master is connected, logging info will only be written if the master's level is at least min_debug_level |
| debug_master | from where debug info will be taken |
- See also:
- Dv::DebugSlave
- Examples:
- test-buffer.h.
virtual Dv::Thread::Monitor::~Monitor |
( |
|
) |
[virtual] |
Dv::Thread::Monitor::Monitor |
( |
const Monitor & |
|
) |
[private] |
Member Function Documentation
void Dv::Thread::Monitor::enter |
( |
const std::string * |
msg = 0 |
) |
|
Enter the monitor.
- Exceptions:
-
| std::runtime_error | if this thread already owns the monitor |
void Dv::Thread::Monitor::exit |
( |
const std::string * |
msg = 0 |
) |
|
Exit the monitor.
- Exceptions:
-
| std::runtime_error | if this thread is not the current owner of the monitor |
void Dv::Thread::Monitor::wait |
( |
unsigned int |
condition = 0 |
) |
|
bool Dv::Thread::Monitor::wait |
( |
unsigned int |
condition, |
|
|
time_t |
timeout | |
|
) |
| | |
Wait for a given condition or until timeout millisecs elapsed.
- Parameters:
-
| condition | number of the condition to wait for. |
| timeout | number of milliseconds we are prepared to wait. |
- Returns:
- false if a timeout occured.
- Exceptions:
-
| std::runtime_error | if this thread is not the current owner of the monitor |
void Dv::Thread::Monitor::signal |
( |
unsigned int |
condition = 0 |
) |
const |
void Dv::Thread::Monitor::broadcast |
( |
unsigned int |
condition = 0 |
) |
const |
Signal all threads waiting on this condition.
This function unblocks all the threads blocked on the condition. The unblocked threads compete for the monitor.
- Parameters:
-
- Exceptions:
-
| runtime_error | if this thread is not the current owner of the monitor |
const std::string& Dv::Thread::Monitor::name |
( |
|
) |
const [inline] |
pthread_t Dv::Thread::Monitor::owner |
( |
|
) |
const [inline] |
bool Dv::Thread::Monitor::owned_by_self |
( |
|
) |
const [inline] |
- Returns:
- true iff the current thread is the owner of the monitor.
References owner().
void Dv::Thread::Monitor::check |
( |
const std::string & |
message |
) |
const [private] |
This functions throws a std::runtime_error if the current thread is not the current owner of the monitor.
- Parameters:
-
| message | used as part of runtime_error.what() |
- Exceptions:
-
| std::runtime_error | if this thread is not the current owner of the monitor |
void Dv::Thread::Monitor::check_cond |
( |
const std::string & |
msg, |
|
|
unsigned int |
n | |
|
) |
| | const [private] |
This functions throws a runtime_error if n is not a valid condition of this monitor or if the current thread does not own the monitor.
- Parameters:
-
| msg | used as part of runtime_error.what() |
| n | number of condition to check |
- Exceptions:
-
| std::runtime_error | if this thread is not the current owner of the monitor |
Member Data Documentation
Entry to the monitor is controlled by this mutex semaphore.
Number of conditions of the monitor.
Array of n_conditions_ posix conditions of this monitor.
The documentation for this class was generated from the following file: