#include <archon/util/mutex.H>
Collaboration diagram for Archon::Utilities::Mutex::Lock:
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. |
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).
Definition at line 102 of file mutex.H.
|
Create a mutex lock holder that does not hold a lock. A lock may later me aquired with the 'aquire' method.
|
|
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(). |
|
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(). |