Mutex (Mutual Exclusion, binary semaphore) class.
More...
#include <Mutex.h>
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
Constructor.
- Note:
- A new constructed mutex is unlocked by default
Constructor.
- Parameters:
-
[in] | bCriticalSection | If 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' |
- Note:
- A new constructed mutex is unlocked by default
Member Function Documentation
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"
Locks the mutex, but only wait until timeout.
- Parameters:
-
[in] | nTimeout | Timeout in milliseconds |
- Returns:
- 'true' if successful, 'false' on error
- Note:
- 'nTimeout = 0' means: Return immediately if already locked
- See also:
-
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: