MySQL 8.4.0
Source Code Documentation
locksys::Latches::Unique_sharded_rw_lock Class Reference

A helper wrapper around Shared_rw_lock which simplifies: More...

Public Member Functions

 Unique_sharded_rw_lock ()
 
 ~Unique_sharded_rw_lock ()
 
bool try_x_lock (ut::Location location)
 
bool is_x_blocked_by_our_s ()
 Checks if there is a thread requesting an x-latch waiting for our thread to release its s-latch. More...
 
void x_lock (ut::Location location)
 
void x_unlock ()
 
void s_lock (ut::Location location)
 
void s_unlock ()
 
bool x_own () const
 
bool s_own () const
 

Private Attributes

Sharded_rw_lock rw_lock
 The actual rw_lock implementation doing the heavy lifting. More...
 

Static Private Attributes

static constexpr size_t NOT_IN_USE = std::numeric_limits<size_t>::max()
 The value used for m_shard_id to indicate that current thread did not s-latch any of the rw_lock's shards. More...
 
static thread_local size_t m_shard_id {NOT_IN_USE}
 The id of the rw_lock's shard which this thread has s-latched, or NOT_IN_USE if it has not s-latched any. More...
 

Detailed Description

A helper wrapper around Shared_rw_lock which simplifies:

  • lifecycle by providing constructor and destructor, and
  • s-latching and s-unlatching by keeping track of the shard id used for spreading the contention. There must be at most one instance of this class (the one in the lock_sys), as it uses thread_local-s to remember which shard of sharded rw lock was used by this thread to perform s-latching (so, hypothetical other instances would share this field, overwriting it and leading to errors).

Constructor & Destructor Documentation

◆ Unique_sharded_rw_lock()

locksys::Latches::Unique_sharded_rw_lock::Unique_sharded_rw_lock ( )

◆ ~Unique_sharded_rw_lock()

locksys::Latches::Unique_sharded_rw_lock::~Unique_sharded_rw_lock ( )

Member Function Documentation

◆ is_x_blocked_by_our_s()

bool locksys::Latches::Unique_sharded_rw_lock::is_x_blocked_by_our_s ( )
inline

Checks if there is a thread requesting an x-latch waiting for our thread to release its s-latch.

Must be called while holding an s-latch.

Returns
true iff there is an x-latcher blocked by our s-latch.

◆ s_lock()

void locksys::Latches::Unique_sharded_rw_lock::s_lock ( ut::Location  location)
inline

◆ s_own()

bool locksys::Latches::Unique_sharded_rw_lock::s_own ( ) const
inline

◆ s_unlock()

void locksys::Latches::Unique_sharded_rw_lock::s_unlock ( )
inline

◆ try_x_lock()

bool locksys::Latches::Unique_sharded_rw_lock::try_x_lock ( ut::Location  location)
inline

◆ x_lock()

void locksys::Latches::Unique_sharded_rw_lock::x_lock ( ut::Location  location)
inline

◆ x_own()

bool locksys::Latches::Unique_sharded_rw_lock::x_own ( ) const
inline

◆ x_unlock()

void locksys::Latches::Unique_sharded_rw_lock::x_unlock ( )
inline

Member Data Documentation

◆ m_shard_id

thread_local size_t locksys::Latches::Unique_sharded_rw_lock::m_shard_id {NOT_IN_USE}
staticprivate

The id of the rw_lock's shard which this thread has s-latched, or NOT_IN_USE if it has not s-latched any.

◆ NOT_IN_USE

constexpr size_t locksys::Latches::Unique_sharded_rw_lock::NOT_IN_USE = std::numeric_limits<size_t>::max()
staticconstexprprivate

The value used for m_shard_id to indicate that current thread did not s-latch any of the rw_lock's shards.

◆ rw_lock

Sharded_rw_lock locksys::Latches::Unique_sharded_rw_lock::rw_lock
private

The actual rw_lock implementation doing the heavy lifting.


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