Dv::Thread::FlexLock Class Reference

Convenience class to synchronize access to a Monitor object. More...

#include <flexlock.h>

Inheritance diagram for Dv::Thread::FlexLock:
Inheritance graph
[legend]
Collaboration diagram for Dv::Thread::FlexLock:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FlexLock (Monitor &m, const std::string &msg="")
 Constructor.
 ~FlexLock ()
 Destructor.
bool entered () const

Private Member Functions

Debugabledebug_master () const

Private Attributes

Monitormonitor_
 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.

Detailed Description

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
       ..
     }
   ...
 };
See also:
Dv::Thread::Lock

Constructor & Destructor Documentation

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.

Parameters:
m monitor to enter.
msg optional message to print to log
See also:
Monitor::enter
Dv::Thread::FlexLock::~FlexLock (  ) 

Destructor.

This function will exit the monitor.

Exceptions:
runtime_error if the current thread is not in the monitor (e.g. if m.exit() was called before the destructor of the Lock).
See also:
Monitor::exit()

Member Function Documentation

bool Dv::Thread::FlexLock::entered (  )  const [inline]
Returns:
true iff the constructor actually entered the monitor.

References entered_.

Debugable* Dv::Thread::FlexLock::debug_master (  )  const [inline, private, virtual]

Reimplemented from Dv::DebugSlave.

References monitor_.


Member Data Documentation

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.

If non-zero, pointer to stream on which to log info.

Was the monitor actually entered upon construction.

Referenced by entered().


The documentation for this class was generated from the following file:

dvthread-0.13.4 [11 December, 2009]