#include <cxxtools/mutex.h>

Public Member Functions | |
| MutexLock (Mutex &m, bool doLock=true, bool isLocked=false) | |
| Construct to guard a Mutex. | |
| ~MutexLock () | |
| Unlocks the mutex unless unlock() was called. | |
| void | lock () |
| void | unlock () |
| Unlock so that the destructor does not unlock. | |
| Mutex & | mutex () |
| Returns the guarded the mutex object. | |
| const Mutex & | mutex () const |
| Returns the guarded the mutex object. | |
// example how to make a member function thread-safe #include <cxxtools/System/Mutex.h> class MyClass { public: void function() { MutexLock lock(_mtx); // // protected operations // // dtor of MutexLock unlocks _mtx } private: cxxtools::System::Mutex _mtx; };
Constructs a MutexLock object and locks the enclosing mutex if doLock is true. If isLocked is true, the MutexLock will only unlock the given mutex in the destructor, but not lock it in the constructor.