QuantumLibrary
Bloomberg::quantum::SpinLock Class Reference

Coroutine-compatible spinlock. Used internally for mutexes since threads running coroutines cannot block. More...

#include <quantum_spinlock.h>

Classes

class  Guard
 
class  ReverseGuard
 

Public Types

using TryToLock = std::try_to_lock_t
 

Public Member Functions

 SpinLock ()
 Constructor. The object is in the unlocked state. More...
 
 SpinLock (const SpinLock &)=delete
 Copy constructor. More...
 
 SpinLock (SpinLock &&)=default
 Move constructor. More...
 
SpinLockoperator= (const SpinLock &)=delete
 Copy assignment operator. More...
 
SpinLockoperator= (SpinLock &&)=default
 Move assignment operator. More...
 
void lock ()
 Locks this object. More...
 
bool tryLock ()
 Attempt to acquire the lock. More...
 
void unlock ()
 Unlocks the current object. More...
 

Detailed Description

Coroutine-compatible spinlock. Used internally for mutexes since threads running coroutines cannot block.

Member Typedef Documentation

◆ TryToLock

using Bloomberg::quantum::SpinLock::TryToLock = std::try_to_lock_t

Constructor & Destructor Documentation

◆ SpinLock() [1/3]

Bloomberg::quantum::SpinLock::SpinLock ( )
inline

Constructor. The object is in the unlocked state.

◆ SpinLock() [2/3]

Bloomberg::quantum::SpinLock::SpinLock ( const SpinLock )
delete

Copy constructor.

◆ SpinLock() [3/3]

Bloomberg::quantum::SpinLock::SpinLock ( SpinLock &&  )
default

Move constructor.

Member Function Documentation

◆ lock()

void Bloomberg::quantum::SpinLock::lock ( )

Locks this object.

Note
Blocks the current thread until the lock is acquired. Blocking is achieved via a busy loop and the thread is not re-scheduled by the operating system.

◆ operator=() [1/2]

SpinLock& Bloomberg::quantum::SpinLock::operator= ( const SpinLock )
delete

Copy assignment operator.

◆ operator=() [2/2]

SpinLock& Bloomberg::quantum::SpinLock::operator= ( SpinLock &&  )
default

Move assignment operator.

◆ tryLock()

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

Attempt to acquire the lock.

Returns
True if successful, false otherwise.
Note
This function never blocks.

◆ unlock()

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

Unlocks the current object.

Note
Never blocks.