#include <Mutex.h>
Inheritance diagram for util::AutoMutex:

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