Archon::Utilities::Mutex::Lock Struct Reference

A mutex lock holder. More...

#include <archon/util/mutex.H>

Collaboration diagram for Archon::Utilities::Mutex::Lock:

Collaboration graph
List of all members.

Public Member Functions

 Lock ()
 Create a mutex lock holder that does not hold a lock.
 Lock (const Mutex &m)
 Create a mutex lock holder and aquire a lock on the mutex.
 ~Lock ()
void aquire (const Mutex &m)
 Aquire a lock on the specified mutex.
void release ()
 Release the currently held mutex lock.

Detailed Description

A mutex lock holder.

This class is used to lock and unlock a mutex. In the simplest situation it is used like this:

Mutex m;

void f() { ...

{ Mutex::Lock l(m)

// Critical stuff }

... }

That is, The costruction of Lock, when a mutex is passed as argument, locks that mutex. Also, the implicit destruction at the end of its scope unlocks the mutex.

You may also construct a Lock without passing a mutex. This feature together with the availability of the 'aquire' and 'release' methods allows you to do locking that does not strictly follow your scopes while still ensuring that the the lock is release when you leave the scope of the Lock variable eg. when a execption escapes that scope.

Note: The individual Lock variable are not reentrant. That is, only one thread must access a specific Lock variable at any time (this includes the implicit destruction).

See also:


Definition at line 102 of file mutex.H.

Constructor & Destructor Documentation

Archon::Utilities::Mutex::Lock::Lock  )  [inline]

Create a mutex lock holder that does not hold a lock.

A lock may later me aquired with the 'aquire' method.

See also:

Definition at line 110 of file mutex.H.

Member Function Documentation

void Archon::Utilities::Mutex::Lock::aquire const Mutex m  )  [inline]

Aquire a lock on the specified mutex.

If another lock was already held it is first released.

Definition at line 129 of file mutex.H.

References Archon::Utilities::Mutex::lock(), and release().

Referenced by Archon::X3D::SAI::Session::ExternalEventQueue::main().

void Archon::Utilities::Mutex::Lock::release  )  [inline]

Release the currently held mutex lock.

If no lock was held, nothing is done.

Definition at line 140 of file mutex.H.

References Archon::Utilities::Mutex::unlock().

Referenced by aquire(), Archon::Utilities::Job::Queue::cancel(), Archon::X3D::SAI::Session::ExternalEventQueue::main(), Archon::Utilities::Stream::BasicPipe< char >::read(), Archon::X3D::Route::refDispose(), Archon::X3D::SAI::ExternalRoute::refDispose(), Archon::Utilities::BackRefObjectBase::refDispose(), Archon::Utilities::RefObjectBase::refDispose(), Archon::Utilities::Stream::BasicPipe< char >::refDispose(), Archon::Utilities::Web::DefaultClient::request(), Archon::Utilities::Thread::terminate(), Archon::Utilities::Semaphore::up(), Archon::Utilities::Stream::BasicPipe< char >::write(), and ~Lock().

The documentation for this struct was generated from the following file:
Generated on Sun Jul 30 22:57:44 2006 for Archon by  doxygen 1.4.4