PMutex Class Reference

Detailed Description

The PMutex class provides access serialization between threads.

The purpose of a PMutex is to protect an object, data structure or section of code so that only one thread can access it at a time. It is usually best to use a mutex with a PMutexLocker since this makes it easy to ensure that locking and unlocking are performed consistently.

Definition at line 29 of file PMutex.h.

#include <PMutex.h>

Constructor & Destructor Documentation

◆ PMutex() [1/2]

PMutex::PMutex ( bool  isRecursive = false)

Constructs a new mutex.

The mutex is created in an unlocked state. If isRecursive is true, a thread can lock the same mutex multiple times and the mutex won't be unlocked until a corresponding number of Unlock() calls have been made. Otherwise a thread may only lock a mutex once. The default is "non recursive".

◆ PMutex() [2/2]

PMutex::PMutex ( const PMutex other)

Constructs a shared copy of other.

◆ ~PMutex()

virtual PMutex::~PMutex ( )

Destroys this object.

Member Function Documentation

◆ Lock()

void PMutex::Lock ( )

Locks the mutex.

If another thread has locked the mutex then this call will block until that thread has unlocked it. Calling this function multiple times on the same mutex from the same thread is allowed if this mutex is a recursive mutex. If this mutex is a non-recursive mutex, this function will dead-lock when the mutex is locked recursively.

◆ operator=()

PMutex& PMutex::operator= ( const PMutex other)

Performs a shared copy of other to this object.

◆ TryLock()

bool PMutex::TryLock ( )

Attempts to lock the mutex.

If the lock was obtained, this function returns true, otherwise it returns false.

◆ Unlock()

void PMutex::Unlock ( )

Unlocks the mutex.

Attempting to unlock a mutex in a different thread to the one that locked it results in an error.