MySQL 9.1.0
Source Code Documentation
lock::Shared_spin_lock Class Reference

#include <shared_spin_lock.h>

Classes

class  Guard
 Sentry class for Shared_spin_lock to deliver RAII pattern usability. More...
 

Public Types

enum class  enum_lock_acquisition { SL_EXCLUSIVE = 0 , SL_SHARED = 1 , SL_NO_ACQUISITION = 2 }
 

Public Member Functions

 Shared_spin_lock ()=default
 Default class constructor. More...
 
virtual ~Shared_spin_lock ()=default
 Default class destructor. More...
 
Shared_spin_lockacquire_shared ()
 Blocks until the lock is acquired in shared mode. More...
 
Shared_spin_lockacquire_exclusive ()
 Blocks until the lock is acquired in exclusive mode. More...
 
Shared_spin_locktry_shared ()
 Tries to acquire the lock in shared mode. More...
 
Shared_spin_locktry_exclusive ()
 Tries to acquire the lock in exclusive mode. More...
 
Shared_spin_lockrelease_shared ()
 Releases the previously granted shared acquisition request. More...
 
Shared_spin_lockrelease_exclusive ()
 Releases the previously granted exclusive acquisition request. More...
 
bool is_shared_acquisition ()
 Returns whether the lock is acquired for shared access by the invoking thread. More...
 
bool is_exclusive_acquisition ()
 Returns whether the lock is acquired for exclusive access by the invoking thread. More...
 

Private Member Functions

Shared_spin_locktry_or_spin_shared_lock (bool try_and_fail)
 Tries to lock or waits for locking in shared mode and increases the thread-local lock acquisition shared counter. More...
 
Shared_spin_locktry_or_spin_exclusive_lock (bool try_and_fail)
 Tries to lock or waits for locking in shared mode and increases the thread-local lock acquisition shared counter. More...
 
bool try_shared_lock ()
 Tries to acquire in shared mode. More...
 
bool try_exclusive_lock ()
 Tries to acquire in exclusive mode. More...
 
void spin_shared_lock ()
 Blocks until the lock is acquired in shared mode. More...
 
void spin_exclusive_lock ()
 Blocks until the lock is acquired in exclusive mode. More...
 

Static Private Member Functions

static std::map< Shared_spin_lock *, long > & acquired_spins ()
 Returns the thread-local lock counter map. More...
 

Private Attributes

memory::Aligned_atomic< long > m_shared_access {0}
 The total amount of threads accessing in shared mode
More...
 
memory::Aligned_atomic< bool > m_exclusive_access {false}
 Whether or not any thread is accessing in or waiting for exclusive mode. More...
 

Friends

class Shared_spin_lock::Guard
 

Member Enumeration Documentation

◆ enum_lock_acquisition

Enumerator
SL_EXCLUSIVE 
SL_SHARED 
SL_NO_ACQUISITION 

Constructor & Destructor Documentation

◆ Shared_spin_lock()

lock::Shared_spin_lock::Shared_spin_lock ( )
default

Default class constructor.

◆ ~Shared_spin_lock()

virtual lock::Shared_spin_lock::~Shared_spin_lock ( )
virtualdefault

Default class destructor.

Member Function Documentation

◆ acquire_exclusive()

lock::Shared_spin_lock & lock::Shared_spin_lock::acquire_exclusive ( )

Blocks until the lock is acquired in exclusive mode.

Returns
A reference to this object, for chaining purposes.

◆ acquire_shared()

lock::Shared_spin_lock & lock::Shared_spin_lock::acquire_shared ( )

Blocks until the lock is acquired in shared mode.

Returns
A reference to this object, for chaining purposes.

◆ acquired_spins()

std::map< lock::Shared_spin_lock *, long > & lock::Shared_spin_lock::acquired_spins ( )
staticprivate

Returns the thread-local lock counter map.

◆ is_exclusive_acquisition()

bool lock::Shared_spin_lock::is_exclusive_acquisition ( )

Returns whether the lock is acquired for exclusive access by the invoking thread.

Returns
true if the lock was acquired in exclusive mode by the invoking thread

◆ is_shared_acquisition()

bool lock::Shared_spin_lock::is_shared_acquisition ( )

Returns whether the lock is acquired for shared access by the invoking thread.

Returns
true if the lock was acquired in shared mode by the invoking thread

◆ release_exclusive()

lock::Shared_spin_lock & lock::Shared_spin_lock::release_exclusive ( )

Releases the previously granted exclusive acquisition request.

Returns
A reference to this object, for chaining purposes.

◆ release_shared()

lock::Shared_spin_lock & lock::Shared_spin_lock::release_shared ( )

Releases the previously granted shared acquisition request.

Returns
A reference to this object, for chaining purposes.

◆ spin_exclusive_lock()

void lock::Shared_spin_lock::spin_exclusive_lock ( )
private

Blocks until the lock is acquired in exclusive mode.

◆ spin_shared_lock()

void lock::Shared_spin_lock::spin_shared_lock ( )
private

Blocks until the lock is acquired in shared mode.

◆ try_exclusive()

lock::Shared_spin_lock & lock::Shared_spin_lock::try_exclusive ( )

Tries to acquire the lock in exclusive mode.

Returns
A reference to this object, for chaining purposes.

◆ try_exclusive_lock()

bool lock::Shared_spin_lock::try_exclusive_lock ( )
private

Tries to acquire in exclusive mode.

Returns
true if the attempt to acquire the lock in exclusive mode was successful.

◆ try_or_spin_exclusive_lock()

lock::Shared_spin_lock & lock::Shared_spin_lock::try_or_spin_exclusive_lock ( bool  try_and_fail)
private

Tries to lock or waits for locking in shared mode and increases the thread-local lock acquisition shared counter.

Parameters
try_and_failWhether or not to try to lock of wait for acquiring.
Returns
A reference to this object, for chaining purposes.

◆ try_or_spin_shared_lock()

lock::Shared_spin_lock & lock::Shared_spin_lock::try_or_spin_shared_lock ( bool  try_and_fail)
private

Tries to lock or waits for locking in shared mode and increases the thread-local lock acquisition shared counter.

Parameters
try_and_failWhether or not to try to lock of wait for acquiring.
Returns
A reference to this object, for chaining purposes.

◆ try_shared()

lock::Shared_spin_lock & lock::Shared_spin_lock::try_shared ( )

Tries to acquire the lock in shared mode.

Returns
A reference to this object, for chaining purposes.

◆ try_shared_lock()

bool lock::Shared_spin_lock::try_shared_lock ( )
private

Tries to acquire in shared mode.

Returns
true if the attempt to acquire the lock in shared mode was successful.

Friends And Related Function Documentation

◆ Shared_spin_lock::Guard

friend class Shared_spin_lock::Guard
friend

Member Data Documentation

◆ m_exclusive_access

memory::Aligned_atomic<bool> lock::Shared_spin_lock::m_exclusive_access {false}
private

Whether or not any thread is accessing in or waiting for exclusive mode.

◆ m_shared_access

memory::Aligned_atomic<long> lock::Shared_spin_lock::m_shared_access {0}
private

The total amount of threads accessing in shared mode


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