QuantumLibrary
Bloomberg::quantum::Mutex Class Reference

Coroutine-compatible implementation of a mutex. More...

#include <quantum_mutex.h>

Classes

class  Guard
 
class  ReverseGuard
 

Public Member Functions

 Mutex ()
 Default constructor. More...
 
 Mutex (const Mutex &other)=delete
 
Mutexoperator= (const Mutex &other)=delete
 
void lock ()
 Locks this mutex. More...
 
void lock (ICoroSync::Ptr sync)
 Locks this mutex. More...
 
bool tryLock ()
 Tries to lock the mutex object. More...
 
void unlock ()
 Unlock this mutex. More...
 

Detailed Description

Coroutine-compatible implementation of a mutex.

This mutex wraps a specialized form of spinlock. The mutex must be used to protect a critical region which is shared between coroutines and (optionally) other code running in a non-coroutine (i.e. regular threaded) context.

Constructor & Destructor Documentation

◆ Mutex() [1/2]

Bloomberg::quantum::Mutex::Mutex ( )
inline

Default constructor.

Note
Mutex object is in unlocked state.

◆ Mutex() [2/2]

Bloomberg::quantum::Mutex::Mutex ( const Mutex other)
delete

Member Function Documentation

◆ lock() [1/2]

void Bloomberg::quantum::Mutex::lock ( )
inline

Locks this mutex.

The mutex object yields (or conditionally sleeps) the current thread for a short period of time until locking succeeds. See YieldingThreadDuration for more details.

Note
Must be called 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.

◆ lock() [2/2]

void Bloomberg::quantum::Mutex::lock ( ICoroSync::Ptr  sync)
inline

Locks this mutex.

The mutex object yields the current coroutine until locking succeeds.

Parameters
[in]syncPointer to a coroutine synchronization object.
Note
Must be called from a coroutine.

◆ operator=()

Mutex& Bloomberg::quantum::Mutex::operator= ( const Mutex other)
delete

◆ tryLock()

bool Bloomberg::quantum::Mutex::tryLock ( )
inline

Tries to lock the mutex object.

Returns
True if succeeds, false otherwise.

◆ unlock()

void Bloomberg::quantum::Mutex::unlock ( )
inline

Unlock this mutex.