PixelLightAPI  .
Public Member Functions
PLCore::MutexGuard Class Reference

Mutex guard class ("Scoped Locking"-idiom, also known as "synchronized block") More...

#include <MutexGuard.h>

List of all members.

Public Member Functions

 MutexGuard (Mutex &cMutex)
 Constructor.
 MutexGuard (Mutex &cMutex, uint64 nTimeout)
 Constructor.
 ~MutexGuard ()
 Destructor.
bool IsLocked () const
 Returns whether the used mutex was locked successfully.
MutexGetMutex () const
 Returns the used mutex.

Detailed Description

Mutex guard class ("Scoped Locking"-idiom, also known as "synchronized block")

Remarks:
When using a mutex in more complex situations there's the risk that one forgets the unlock a locked mutex. To avoid this situation it's a good idea to use this mutex guard on the runtime stack (the runtime stack is your friend!) in order to lock the mutex and automatically unlock it as soon as the critical scope is left.

Constructor & Destructor Documentation

PLCore::MutexGuard::MutexGuard ( Mutex cMutex) [inline]

Constructor.

Parameters:
[in]cMutexMutex to use, just referenced, must stay valid as long as this mutex guard exists!
Note:
  • Blocking if the mutex is already locked
  • Use the constructor with a timeout to avoid potential deadlocks
PLCore::MutexGuard::MutexGuard ( Mutex cMutex,
uint64  nTimeout 
) [inline]

Constructor.

Parameters:
[in]cMutexMutex to use, just referenced, must stay valid as long as this mutex guard exists!
[in]nTimeoutTimeout in milliseconds
Note:
  • 'nTimeout = 0' means: Return immediately if the mutex is already locked

Destructor.


Member Function Documentation

bool PLCore::MutexGuard::IsLocked ( ) const [inline]

Returns whether the used mutex was locked successfully.

Returns:
'true' if the used mutex was locked successfully, else 'false'
Mutex & PLCore::MutexGuard::GetMutex ( ) const [inline]

Returns the used mutex.

Returns:
The used mutex

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