#include <ScopedLock.h>
The constructor of ScopedLock locks the mutex, the destructor unlocks the mutex. In this way you can safely use ScopedLock inside a try/catch block without worrying about to the lock state of the mutex.
For example:
try { ScopedLock hold(mutex); throw Exception(); } catch (...) { // the mutex is unlocked here } // if you don't throw a exception, the mutex is unlocked here too
Public Member Functions | |
ScopedLock (Mutex &mutex) | |
Creates the ScopedLock locking the specified mutex. | |
~ScopedLock () | |
Destroys the ScopedLock unlocking the held mutex. | |
Mutex & | getMutex () const |
Returns which mutex is being held. | |
Private Member Functions | |
ScopedLock () | |
Private Attributes | |
Mutex & | m_mutex |
Vaca::ScopedLock::ScopedLock | ( | ) | [private] |
Vaca::ScopedLock::ScopedLock | ( | Mutex & | mutex | ) | [inline] |
Creates the ScopedLock locking the specified mutex.
mutex | Mutex to be hold by the ScopedLock's life-time. |
Vaca::ScopedLock::~ScopedLock | ( | ) | [inline] |
Destroys the ScopedLock unlocking the held mutex.
Mutex& Vaca::ScopedLock::getMutex | ( | ) | const [inline] |
Returns which mutex is being held.
Mutex& Vaca::ScopedLock::m_mutex [private] |