PIP 5.6.1
Platform-Independent Primitives
Public Member Functions | List of all members
PIMutexLocker Class Reference

Scope guard that locks a PIMutex in constructor and unlocks it in destructor. More...

#include <pimutex.h>

Public Member Functions

 PIMutexLocker (PIMutex &m, bool condition=true)
 Constructs and lock "m" if "condition" is true.
 
 ~PIMutexLocker ()
 Unlock "m" if "condition" was true.
 

Detailed Description

Scope guard that locks a PIMutex in constructor and unlocks it in destructor.

PIMutex autolocker

When a PIMutexLocker object is created, it attempts to lock the mutex it is given, if "condition" true. When control leaves the scope in which the PIMutexLocker object was created, the PIMutexLocker is destructed and the mutex is released, if "condition" was true.

If "condition" false this class do nothing.

The PIMutexLocker class is non-copyable.

// critical section start
{
PIMutexLocker locker(mutex);
// ... your code here
}
// critical section end
Scope guard that locks a PIMutex in constructor and unlocks it in destructor.
Definition: pimutex.h:75