Base Framework
Public Types | Public Member Functions | List of all members
SpinLock Class Reference

Spin lock (fast). More...

#include <base/concurrency/SpinLock.h>

Inherits Lock.

Inherited by RecursiveSpinLock.

Public Types

typedef ExclusiveSynchronize< SpinLockSync
 
- Public Types inherited from Lock
typedef ExclusiveSynchronize< LockSync
 

Public Member Functions

 SpinLock () noexcept
 
bool invariant () const noexcept
 
void exclusiveLock () const noexcept
 
bool tryExclusiveLock () const noexcept
 
void sharedLock () const noexcept
 
bool trySharedLock () const noexcept
 
void releaseLock () const noexcept
 
- Public Member Functions inherited from Lock
 Lock () noexcept
 
virtual ~Lock ()
 

Detailed Description

Spin lock (fast).

Spin lock is a synchronization object just like MutualExclusion. SpinLock does not use any operating system resources. The SpinLock is fast. The CPU cannot do anything useful while waiting for a spin lock to be released.

See also
MutualExclusion NISpinLock
Version
1.2
Examples
testsuite/Thread.cpp.

Constructor & Destructor Documentation

◆ SpinLock()

SpinLock::SpinLock ( )
noexcept

Initializes spin lock to unlocked state.

Member Function Documentation

◆ exclusiveLock()

void SpinLock::exclusiveLock ( ) const
virtualnoexcept

Acquires an exclusive lock.

Implements Lock.

◆ invariant()

bool SpinLock::invariant ( ) const
noexcept

Returns true if state is valid.

◆ releaseLock()

void SpinLock::releaseLock ( ) const
virtualnoexcept

Releases the spin lock.

Implements Lock.

◆ sharedLock()

void SpinLock::sharedLock ( ) const
inlinevirtualnoexcept

Acquires a shared lock. For some lock implementations this will acquire an exclusive lock.

Implements Lock.

◆ tryExclusiveLock()

bool SpinLock::tryExclusiveLock ( ) const
virtualnoexcept

Tries to acquire an exclusive lock.

Returns
True on success.

Implements Lock.

◆ trySharedLock()

bool SpinLock::trySharedLock ( ) const
inlinevirtualnoexcept

Tries to acquire a shared lock. acquire an exclusive lock.

Returns
True on success.

Implements Lock.