Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::AutoMutex Class Reference

#include <Mutex.h>

Inheritance diagram for util::AutoMutex:

util::Object List of all members.

Detailed Description

AutoMutex is a class for automatically locking and unlocking a mutex.

It comes in handy when there are many places where a mutex should be unlocked and especially with exceptions. AutoMutex locks a mutex when it is created and unlocks it upon deletion.

Example:

 ...
 int foobar(void)
 {
   //mutex is defined elsewhere. Locally defined mutexes make no sense
   AutoMutex auto(mutex); //lock, enter protected area
   if (something)
     return 0; //no need to unlock, AutoMutex takes care
   if (something_else)
     throw 0; //same here
   return 1; //and here
 }
 


Public Methods

 AutoMutex (Mutex &mutex)
 Create a new AutoMutex, lock the mutex.

 ~AutoMutex ()
 Destroy an AutoMutex, unlock the mutex.


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.