Convenience class to synchronize access to a Monitor object. More...
#include <flexlock.h>
Public Member Functions | |
FlexLock (Monitor &m, const std::string &msg="") | |
Constructor. | |
~FlexLock () | |
Destructor. | |
bool | entered () const |
Private Member Functions | |
Debugable * | debug_master () const |
Private Attributes | |
Monitor & | monitor_ |
Monitor on which FlexLock is defined. | |
const std::string | msg_ |
Message to print on construction and destruction. | |
Dv::ostream_ptr | log_ |
If non-zero, pointer to stream on which to log info. | |
bool | entered_ |
Was the monitor actually entered upon construction. |
Convenience class to synchronize access to a Monitor object.
The difference with Dv::Thread::Lock is that if the constructing thread already owns the monitor, it does no attempt to enter it (and does not attempt to exit it upon destruction).
Example usage:
class SomeClassToProtect: public Dv::Thread::Monitor { public: voif f() { FlexLock lock(*this, "f", &cerr); // enter monitor g() // destructor of lock will exit the monitor. } void g() { FlexLock lock(*this, "g", &cerr); // enter monitor, but not if called from f .. } ... };
Dv::Thread::FlexLock::FlexLock | ( | Monitor & | m, | |
const std::string & | msg = "" | |||
) |
Constructor.
This function will enter the monitor parameter unless the current thread is already the owner of the monitor. Writing to FlexLock::log() will write to its monitor's log.
m | monitor to enter. | |
msg | optional message to print to log |
Dv::Thread::FlexLock::~FlexLock | ( | ) |
Destructor.
This function will exit the monitor.
runtime_error | if the current thread is not in the monitor (e.g. if m.exit() was called before the destructor of the Lock). |
bool Dv::Thread::FlexLock::entered | ( | ) | const [inline] |
References entered_.
Debugable* Dv::Thread::FlexLock::debug_master | ( | ) | const [inline, private, virtual] |
Reimplemented from Dv::DebugSlave.
References monitor_.
Monitor& Dv::Thread::FlexLock::monitor_ [private] |
Monitor on which FlexLock is defined.
Referenced by debug_master().
const std::string Dv::Thread::FlexLock::msg_ [private] |
Message to print on construction and destruction.
Dv::ostream_ptr Dv::Thread::FlexLock::log_ [private] |
If non-zero, pointer to stream on which to log info.
bool Dv::Thread::FlexLock::entered_ [private] |
Was the monitor actually entered upon construction.
Referenced by entered().
dvthread-0.13.4 | [11 December, 2009] |