A guard class. More...
#include <Radiant/Mutex.hpp>
Public Member Functions | |
| Guard (Mutex &mutex) | |
| Construct guard. More... | |
| ~Guard () | |
| Destructor, unlocks the associated mutex. | |
A guard class.
This class is used to automatically lock and unlock a mutex within some function. This is useful when trying to avoid situations where there are several "return"-statements in a function, and one easily forget to unlock the mutex that one is using.
int MyClass::doSomething()
{
Mutex is locked here:
Guarg g(mutex());Mutex is freed reliably on each return path if(foo()) return 0; if(fee()) return 1; return 2; }
|
inline |
Construct guard.
Locks the given mutex.
| mutex | mutex to guard |