QuantumLibrary
Bloomberg::quantum::SpinLock::Guard Class Reference

#include <quantum_spinlock.h>

Public Member Functions

 Guard (SpinLock &lock)
 Construct this object and lock the passed-in spinlock. More...
 
 Guard (SpinLock &lock, SpinLock::TryToLock)
 Construct this object and tries to lock the passed-in spinlock. More...
 
 ~Guard ()
 Destroy this object and unlock the underlying spinlock. More...
 
void lock ()
 Acquire the underlying spinlock. More...
 
bool tryLock ()
 Try to acquire the underlying spinlock. More...
 
bool ownsLock () const
 Indicates if this object owns the underlying spinlock. More...
 

Constructor & Destructor Documentation

◆ Guard() [1/2]

SpinLock::Guard::Guard ( SpinLock lock)
inlineexplicit

Construct this object and lock the passed-in spinlock.

Parameters
[in]lockSpinlock which protects a scope during the lifetime of the Guard.
Note
Blocks the current thread until the spinlock is acquired.

◆ Guard() [2/2]

SpinLock::Guard::Guard ( SpinLock lock,
SpinLock::TryToLock   
)
inline

Construct this object and tries to lock the passed-in spinlock.

Parameters
[in]lockSpinlock which protects a scope during the lifetime of the Guard.
Note
Attempts to lock the spinlock. Does not block.

◆ ~Guard()

SpinLock::Guard::~Guard ( )
inline

Destroy this object and unlock the underlying spinlock.

Member Function Documentation

◆ lock()

void SpinLock::Guard::lock ( )
inline

Acquire the underlying spinlock.

Note
Blocks.

◆ ownsLock()

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

Indicates if this object owns the underlying spinlock.

Returns
True if ownership is acquired.

◆ tryLock()

bool SpinLock::Guard::tryLock ( )
inline

Try to acquire the underlying spinlock.

Returns
True if spinlock is locked, false otherwise.
Note
Does not block.