Mutex synchronization primitive.
More...
#include <mutex.h>
Mutex synchronization primitive.
A mutex object facilitates protection against data races and allows thread-safe synchronization of data between threads. A thread obtains ownership of a mutex object by calling one of the lock functions and relinquishes ownership by calling the corresponding unlock function.
Thread-safe.
https://en.wikipedia.org/wiki/Mutual_exclusion
- Examples
- threads_mutex.cpp.
Definition at line 29 of file mutex.h.
◆ Mutex() [1/3]
CppCommon::Mutex::Mutex |
( |
| ) |
|
◆ Mutex() [2/3]
CppCommon::Mutex::Mutex |
( |
const Mutex & |
| ) |
|
|
delete |
◆ Mutex() [3/3]
CppCommon::Mutex::Mutex |
( |
Mutex && |
mutex | ) |
|
|
delete |
◆ ~Mutex()
CppCommon::Mutex::~Mutex |
( |
| ) |
|
◆ Lock()
void CppCommon::Mutex::Lock |
( |
| ) |
|
Acquire mutex with block.
Will block.
Definition at line 170 of file mutex.cpp.
◆ operator=() [1/2]
Mutex& CppCommon::Mutex::operator= |
( |
const Mutex & |
| ) |
|
|
delete |
◆ operator=() [2/2]
Mutex& CppCommon::Mutex::operator= |
( |
Mutex && |
mutex | ) |
|
|
delete |
◆ TryLock()
bool CppCommon::Mutex::TryLock |
( |
| ) |
|
Try to acquire mutex without block.
Will not block.
- Returns
- 'true' if the mutex was successfully acquired, 'false' if the mutex is busy
Definition at line 167 of file mutex.cpp.
◆ TryLockFor()
bool CppCommon::Mutex::TryLockFor |
( |
const Timespan & |
timespan | ) |
|
Try to acquire mutex for the given timespan.
Will block for the given timespan in the worst case.
- Parameters
-
timespan | - Timespan to wait for the mutex |
- Returns
- 'true' if the mutex was successfully acquired, 'false' if the mutex is busy
Definition at line 168 of file mutex.cpp.
◆ TryLockUntil()
bool CppCommon::Mutex::TryLockUntil |
( |
const UtcTimestamp & |
timestamp | ) |
|
|
inline |
Try to acquire mutex until the given timestamp.
Will block until the given timestamp in the worst case.
- Parameters
-
timestamp | - Timestamp to stop wait for the mutex |
- Returns
- 'true' if the mutex was successfully acquired, 'false' if the mutex is busy
Definition at line 63 of file mutex.h.
◆ Unlock()
void CppCommon::Mutex::Unlock |
( |
| ) |
|
Release mutex.
Will not block.
Definition at line 171 of file mutex.cpp.
The documentation for this class was generated from the following files: