MutexLock Class Reference

#include <Pt/System/Mutex.h>

Scoped lock for a Mutex. More...

Inherits NonCopyable.

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 ()
 Lock the mutex.
void unlock ()
 Unlock so that the destructor does not unlock.
Mutexmutex ()
 Returns the guarded the mutex object.
const Mutexmutex () const
 Returns the guarded the mutex object.

Detailed Description

MutexLock locks a Mutex in the constructor and unlocks it in the destructor, including during stack unwinding.

Constructor & Destructor Documentation

◆ MutexLock()

MutexLock ( Mutex & m,
bool doLock = true,
bool isLocked = false )

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.