PixelLightAPI  .
Public Member Functions
PLCore::Mutex Class Reference

Mutex (Mutual Exclusion, binary semaphore) class. More...

#include <Mutex.h>

Inheritance diagram for PLCore::Mutex:
Inheritance graph
[legend]

List of all members.

Public Member Functions

PLCORE_API Mutex ()
 Constructor.
PLCORE_API Mutex (bool bCriticalSection)
 Constructor.
PLCORE_API ~Mutex ()
 Destructor.
bool Lock ()
 Locks the mutex.
bool TryLock (uint64 nTimeout)
 Locks the mutex, but only wait until timeout.
bool Unlock ()
 Unlocks the mutex.

Detailed Description

Mutex (Mutual Exclusion, binary semaphore) class.

Note:
  • Implementation of the bridge design pattern, this class is the abstraction
  • The mutex is non-recursive, meaning that you have to be careful to avoid creating a "self-deadlock" by calling the lock method multiple times directly or indirectly by other method calls
  • It's a good idea to lock/unlock a mutex by using the MutexGuard helper class on the runtime stack so there's always an unlock for each lock!

Constructor & Destructor Documentation

PLCORE_API PLCore::Mutex::Mutex ( )

Constructor.

Note:
  • A new constructed mutex is unlocked by default
PLCORE_API PLCore::Mutex::Mutex ( bool  bCriticalSection)

Constructor.

Parameters:
[in]bCriticalSectionIf supported by the platform: 'true' to use "Critical Section" (lock/unlock only inside the same process) instead of "Mutex" (lock/unlock across multiple processes) implementation, else 'false'
Remarks:
Platforms handle mutual exclusion implementations differently. POSIX only offers "Mutex", while MS Windows makes a difference between "Mutex" (lock/unlock across multiple processes) and "Critical Section" (lock/unlock only inside the same process).
Note:
  • A new constructed mutex is unlocked by default
PLCORE_API PLCore::Mutex::~Mutex ( )

Destructor.


Member Function Documentation

bool PLCore::Mutex::Lock ( ) [inline]

Locks the mutex.

Returns:
'true' if successful, 'false' on error
Note:
  • Blocking if already locked
  • Use the lock method with a timeout to avoid potential deadlocks
  • In the literature, this operation is also known as "acquire"
bool PLCore::Mutex::TryLock ( uint64  nTimeout) [inline]

Locks the mutex, but only wait until timeout.

Parameters:
[in]nTimeoutTimeout in milliseconds
Returns:
'true' if successful, 'false' on error
Note:
  • 'nTimeout = 0' means: Return immediately if already locked
See also:
bool PLCore::Mutex::Unlock ( ) [inline]

Unlocks the mutex.

Returns:
'true' if successful, 'false' on error
Note:
  • In the literature, this operation is also known as "release"

The documentation for this class was generated from the following files:


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:16
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported