#include <quantum_mutex.h>
◆ Guard() [1/2]
Mutex::Guard::Guard |
( |
Mutex & |
mutex, |
|
|
bool |
tryLock = false |
|
) |
| |
|
inlineexplicit |
Construct this object and lock the passed-in mutex.
- Parameters
-
[in] | mutex | Mutex which protects a scope during the lifetime of the Guard. |
[in] | tryLock | If set to true, tries to lock the mutex instead of unconditionally locking it. |
- Note
- If tryLock is set to true, ownership of the mutex may fail in which case it can be verified with ownsLock(). This constructor must be used in a non-coroutine context.
- Warning
- Wrongfully calling this method from a coroutine will block all coroutines running in the same queue and thus result in noticeable performance degradation.
◆ Guard() [2/2]
Construct this object and lock the passed-in mutex.
- Parameters
-
[in] | sync | Pointer to a coroutine synchronization object. |
[in] | mutex | Mutex which protects a scope during the lifetime of the Guard. |
[in] | tryLock | If set to true, tries to lock the mutex instead of unconditionally locking it. |
- Note
- If tryLock is set to true, ownership of the mutex may fail in which case it can be verified with ownsLock(). This constructor must be used in a coroutine context.
◆ ~Guard()
Destructor. This will unlock the underlying mutex.
◆ ownsLock()
bool Mutex::Guard::ownsLock |
( |
| ) |
const |
|
inline |
Determines if this object owns the underlying mutex.
- Returns
- True if mutex is locked, false otherwise.