MySQL 26.7.0
Source Code Documentation
mysql::concurrency::Spin_lock_mutex Class Reference

Implementation of a spin-lock mutex. More...

#include <spin_lock_mutex.h>

Public Member Functions

 Spin_lock_mutex (const Spin_lock_mutex &)=delete
 
 Spin_lock_mutex (Spin_lock_mutex &&)=delete
 
Spin_lock_mutexoperator= (const Spin_lock_mutex &src)=delete
 
Spin_lock_mutexoperator= (Spin_lock_mutex &&src)=delete
 
 Spin_lock_mutex (Mutex_key key={})
 
 ~Spin_lock_mutex ()=default
 
void lock () noexcept
 Acquire a lock, blocks access to a critical section until "unlock" is called. More...
 
bool try_lock () noexcept
 Non-blocking try-lock operation. More...
 
void unlock ()
 Unblocks access to a critical section for other threads. More...
 

Static Private Member Functions

static void spin_yield () noexcept
 

Private Attributes

std::atomic_flag m_lock = ATOMIC_FLAG_INIT
 Internal synchronization boolean, true means that lock is currently owned Since C++20, default constructor sets atomic_flag to "clear" state We use atomic_flag because it is guaranteed to be lock free. More...
 

Detailed Description

Implementation of a spin-lock mutex.

Satisfies requirements of Mutex

  • Lockable
  • DefaultConstructible
  • Destructible
  • not copyable
  • not movable
    Note
    Use with care. In general, is not recommended to use spin locks over mutexes. Spin locks should be used only when expected contention is minimal (e.g. when combining with strip-locking techniques).

Constructor & Destructor Documentation

◆ Spin_lock_mutex() [1/3]

mysql::concurrency::Spin_lock_mutex::Spin_lock_mutex ( const Spin_lock_mutex )
delete

◆ Spin_lock_mutex() [2/3]

mysql::concurrency::Spin_lock_mutex::Spin_lock_mutex ( Spin_lock_mutex &&  )
delete

◆ Spin_lock_mutex() [3/3]

mysql::concurrency::Spin_lock_mutex::Spin_lock_mutex ( Mutex_key  key = {})
inline

◆ ~Spin_lock_mutex()

mysql::concurrency::Spin_lock_mutex::~Spin_lock_mutex ( )
default

Member Function Documentation

◆ lock()

void mysql::concurrency::Spin_lock_mutex::lock ( )
noexcept

Acquire a lock, blocks access to a critical section until "unlock" is called.

◆ operator=() [1/2]

Spin_lock_mutex & mysql::concurrency::Spin_lock_mutex::operator= ( const Spin_lock_mutex src)
delete

◆ operator=() [2/2]

Spin_lock_mutex & mysql::concurrency::Spin_lock_mutex::operator= ( Spin_lock_mutex &&  src)
delete

◆ spin_yield()

static void mysql::concurrency::Spin_lock_mutex::spin_yield ( )
inlinestaticprivatenoexcept

◆ try_lock()

bool mysql::concurrency::Spin_lock_mutex::try_lock ( )
noexcept

Non-blocking try-lock operation.

Return values
trueLock has been acquired
falseLock has NOT been acquired

◆ unlock()

void mysql::concurrency::Spin_lock_mutex::unlock ( )

Unblocks access to a critical section for other threads.

Member Data Documentation

◆ m_lock

std::atomic_flag mysql::concurrency::Spin_lock_mutex::m_lock = ATOMIC_FLAG_INIT
private

Internal synchronization boolean, true means that lock is currently owned Since C++20, default constructor sets atomic_flag to "clear" state We use atomic_flag because it is guaranteed to be lock free.


The documentation for this class was generated from the following files: