Dv::Thread::Lock Class Reference

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

#include <lock.h>

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

List of all members.

Public Member Functions

 Lock (Monitor &m, const std::string &msg="")
 Constructor.
 ~Lock ()
 Destructor.
Debugabledebug_master () const

Private Attributes

Monitormonitor_
 Monitor on which lock is defined.
const std::string msg_
 Message to print on construction and destruction.

Detailed Description

Convenience class to synchronize access to a Monitor object.

Creating a lock enters the monitor, destroying the lock exits the monitor.

Example usage:

 class SomeClassToProtect: public Dv::Thread::Monitor {
 public:
   voif f() {
     Lock  lock(*this, "f", &cerr); // enter monitor
     access the object
     // destructor of lock will exit the monitor.
     }
 ...
 };
Examples:

test-buffer.h, and test-pool.C.


Constructor & Destructor Documentation

Dv::Thread::Lock::Lock ( Monitor m,
const std::string &  msg = "" 
)

Constructor.

This function will enter the monitor parameter.

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

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

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

Reimplemented from Dv::DebugSlave.

References monitor_.


Member Data Documentation

Monitor on which lock is defined.

Referenced by debug_master().

const std::string Dv::Thread::Lock::msg_ [private]

Message to print on construction and destruction.


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

dvthread-0.13.4 [11 December, 2009]