MySQL 9.1.0
Source Code Documentation
Sharded_rw_lock Class Reference

Rw-lock with very fast, highly concurrent s-lock but slower x-lock. More...

#include <sync0sharded_rw.h>

Public Member Functions

void create (mysql_pfs_key_t pfs_key, latch_id_t latch_id, size_t n_shards)
 
void free ()
 
size_t s_lock (ut::Location location)
 
void s_unlock (size_t shard_no)
 
bool is_x_blocked_by_s (size_t shard_no)
 Checks if there is a thread requesting an x-latch waiting for threads to release their s-latches on given shard. More...
 
bool try_x_lock (ut::Location location)
 Tries to obtain exclusive latch - similar to x_lock(), but non-blocking, and thus can fail. More...
 
void x_lock (ut::Location location)
 
void x_unlock ()
 
bool s_own (size_t shard_no) const
 
bool x_own () const
 

Private Types

using Shard = ut::Cacheline_padded< rw_lock_t >
 

Private Member Functions

template<typename F >
void for_each (F f)
 

Private Attributes

Shardm_shards = nullptr
 
size_t m_n_shards = 0
 

Detailed Description

Rw-lock with very fast, highly concurrent s-lock but slower x-lock.

It's basically array of rw-locks. When s-lock is being acquired, single rw-lock from array is selected randomly and s-locked. Therefore, all rw-locks from array has to be x-locked when x-lock is being acquired.

Purpose of this data structure is to reduce contention on single atomic in single rw-lock when a lot of threads need to acquire s-lock very often, but x-lock is very rare.

Member Typedef Documentation

◆ Shard

Member Function Documentation

◆ create()

void Sharded_rw_lock::create ( mysql_pfs_key_t  pfs_key,
latch_id_t  latch_id,
size_t  n_shards 
)
inline

◆ for_each()

template<typename F >
void Sharded_rw_lock::for_each ( f)
inlineprivate

◆ free()

void Sharded_rw_lock::free ( )
inline

◆ is_x_blocked_by_s()

bool Sharded_rw_lock::is_x_blocked_by_s ( size_t  shard_no)
inline

Checks if there is a thread requesting an x-latch waiting for threads to release their s-latches on given shard.

Parameters
[in]shard_noThe shard to check.
Returns
true iff there is an x-latcher blocked by s-latchers on shard_no.

◆ s_lock()

size_t Sharded_rw_lock::s_lock ( ut::Location  location)
inline

◆ s_own()

bool Sharded_rw_lock::s_own ( size_t  shard_no) const
inline

◆ s_unlock()

void Sharded_rw_lock::s_unlock ( size_t  shard_no)
inline

◆ try_x_lock()

bool Sharded_rw_lock::try_x_lock ( ut::Location  location)
inline

Tries to obtain exclusive latch - similar to x_lock(), but non-blocking, and thus can fail.

Returns
true iff succeeded to acquire the exclusive latch

◆ x_lock()

void Sharded_rw_lock::x_lock ( ut::Location  location)
inline

◆ x_own()

bool Sharded_rw_lock::x_own ( ) const
inline

◆ x_unlock()

void Sharded_rw_lock::x_unlock ( )
inline

Member Data Documentation

◆ m_n_shards

size_t Sharded_rw_lock::m_n_shards = 0
private

◆ m_shards

Shard* Sharded_rw_lock::m_shards = nullptr
private

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