QuantumLibrary
Bloomberg::quantum::Mutex::Guard Class Reference

#include <quantum_mutex.h>

Public Member Functions

 Guard (Mutex &mutex, bool tryLock=false)
 Construct this object and lock the passed-in mutex. More...
 
 Guard (ICoroSync::Ptr sync, Mutex &mutex, bool tryLock=false)
 Construct this object and lock the passed-in mutex. More...
 
 ~Guard ()
 Destructor. This will unlock the underlying mutex. More...
 
bool ownsLock () const
 Determines if this object owns the underlying mutex. More...
 

Constructor & Destructor Documentation

◆ Guard() [1/2]

Mutex::Guard::Guard ( Mutex mutex,
bool  tryLock = false 
)
inlineexplicit

Construct this object and lock the passed-in mutex.

Parameters
[in]mutexMutex which protects a scope during the lifetime of the Guard.
[in]tryLockIf 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]

Mutex::Guard::Guard ( ICoroSync::Ptr  sync,
Mutex mutex,
bool  tryLock = false 
)
inline

Construct this object and lock the passed-in mutex.

Parameters
[in]syncPointer to a coroutine synchronization object.
[in]mutexMutex which protects a scope during the lifetime of the Guard.
[in]tryLockIf 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()

Mutex::Guard::~Guard ( )
inline

Destructor. This will unlock the underlying mutex.

Member Function Documentation

◆ ownsLock()

bool Mutex::Guard::ownsLock ( ) const
inline

Determines if this object owns the underlying mutex.

Returns
True if mutex is locked, false otherwise.