MySQL 8.4.2
Source Code Documentation
rw_lock_t Struct Reference

The structure used in the spin lock implementation of a read-write lock. More...

#include <sync0rw.h>

Inheritance diagram for rw_lock_t:
[legend]

Public Member Functions

 rw_lock_t ()=default
 
 rw_lock_t (const rw_lock_t &)=delete
 rw_lock_t is not a copyable object, the reasoning behind this is the same as the reasoning behind why std::mutex is not copyable. More...
 
rw_lock_toperator= (const rw_lock_t &)=delete
 
void decrement_sx_recursive ()
 
uint64_t increment_sx_recursive ()
 
 UT_LIST_NODE_T (rw_lock_t) list
 All allocated rw locks are put into a list. More...
 
 ~rw_lock_t () override
 Destructor. More...
 
virtual std::string to_string () const override
 Print the rw-lock information. More...
 
virtual std::string locked_from () const override
 Print where it was locked from. More...
 
 UT_LIST_BASE_NODE_T (rw_lock_debug_t, list) debug_list
 In the debug version: pointer to the debug info list of the lock. More...
 
bool is_x_blocked_by_s ()
 Checks if there is a thread requesting an x-latch waiting for threads to release their s-latches. More...
 
- Public Member Functions inherited from latch_t
 latch_t (latch_id_t id=LATCH_ID_NONE) 1
 Constructor. More...
 
latch_toperator= (const latch_t &)=default
 
virtual ~latch_t () 1=default
 Destructor. More...
 
latch_id_t get_id () const
 
bool is_rw_lock () const 1
 
latch_level_t get_level () const 1
 
bool is_temp_fsp () const 1
 
void set_temp_fsp () 1
 Set the temporary tablespace flag. More...
 
const char * get_name () const 1
 

Public Attributes

std::atomic< int32_t > lock_word
 Holds the state of the lock. More...
 
std::atomic< bool > waiters
 1: there are waiters More...
 
std::atomic< bool > recursive
 Default value false which means the lock is non-recursive. More...
 
std::atomic< uint64_t > sx_recursive
 number of granted SX locks. More...
 
std::atomic< std::thread::idwriter_thread
 Thread id of writer thread. More...
 
Atomic_xor_of_thread_id reader_thread
 XOR of reader threads' IDs. More...
 
os_event_t event
 Used by sync0arr.cc for thread queueing. More...
 
os_event_t wait_ex_event
 Event for next-writer to wait on. More...
 
ut::Location clocation
 Location where lock created. More...
 
const char * last_s_file_name
 last s-lock file/line is not guaranteed to be correct More...
 
const char * last_x_file_name
 File name where last x-locked. More...
 
bool is_block_lock
 If 1 then the rw-lock is a block lock. More...
 
uint16_t last_s_line
 Line number where last time s-locked. More...
 
uint16_t last_x_line
 Line number where last time x-locked. More...
 
uint32_t count_os_wait
 Count of os_waits. More...
 
struct PSI_rwlockpfs_psi
 The instrumentation hook. More...
 
uint32_t magic_n = {MAGIC_N}
 
- Public Attributes inherited from latch_t
latch_id_t m_id
 Latch ID. More...
 
bool m_rw_lock
 true if it is a rw-lock. More...
 
bool m_temp_fsp
 true if it is an temporary space latch More...
 

Static Public Attributes

static const uint32_t MAGIC_N = 22643
 For checking memory corruption. More...
 

Detailed Description

The structure used in the spin lock implementation of a read-write lock.

Several threads may have a shared lock simultaneously in this lock, but only one writer may have an exclusive lock, in which case no shared locks are allowed. To prevent starving of a writer blocked by readers, a writer may queue for x-lock by decrementing lock_word: no new readers will be let in while the thread waits for readers to exit.

Constructor & Destructor Documentation

◆ rw_lock_t() [1/2]

rw_lock_t::rw_lock_t ( )
default

◆ rw_lock_t() [2/2]

rw_lock_t::rw_lock_t ( const rw_lock_t )
delete

rw_lock_t is not a copyable object, the reasoning behind this is the same as the reasoning behind why std::mutex is not copyable.

It is supposed to represent a synchronization primitive for which copying semantics do not make sense.

◆ ~rw_lock_t()

rw_lock_t::~rw_lock_t ( )
override

Destructor.

Member Function Documentation

◆ decrement_sx_recursive()

void rw_lock_t::decrement_sx_recursive ( )
inline

◆ increment_sx_recursive()

uint64_t rw_lock_t::increment_sx_recursive ( )
inline

◆ is_x_blocked_by_s()

bool rw_lock_t::is_x_blocked_by_s ( )
inline

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

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

◆ locked_from()

std::string rw_lock_t::locked_from ( ) const
overridevirtual

Print where it was locked from.

Returns
the string representation

Implements latch_t.

◆ operator=()

rw_lock_t & rw_lock_t::operator= ( const rw_lock_t )
delete

◆ to_string()

std::string rw_lock_t::to_string ( ) const
overridevirtual

Print the rw-lock information.

Returns
the string representation

Implements latch_t.

◆ UT_LIST_BASE_NODE_T()

rw_lock_t::UT_LIST_BASE_NODE_T ( rw_lock_debug_t  ,
list   
)
inline

In the debug version: pointer to the debug info list of the lock.

◆ UT_LIST_NODE_T()

rw_lock_t::UT_LIST_NODE_T ( rw_lock_t  )

All allocated rw locks are put into a list.

Member Data Documentation

◆ clocation

ut::Location rw_lock_t::clocation

Location where lock created.

◆ count_os_wait

uint32_t rw_lock_t::count_os_wait

Count of os_waits.

May not be accurate

◆ event

os_event_t rw_lock_t::event

Used by sync0arr.cc for thread queueing.

◆ is_block_lock

bool rw_lock_t::is_block_lock

If 1 then the rw-lock is a block lock.

◆ last_s_file_name

const char* rw_lock_t::last_s_file_name

last s-lock file/line is not guaranteed to be correct

◆ last_s_line

uint16_t rw_lock_t::last_s_line

Line number where last time s-locked.

◆ last_x_file_name

const char* rw_lock_t::last_x_file_name

File name where last x-locked.

◆ last_x_line

uint16_t rw_lock_t::last_x_line

Line number where last time x-locked.

◆ lock_word

std::atomic<int32_t> rw_lock_t::lock_word

Holds the state of the lock.

◆ MAGIC_N

const uint32_t rw_lock_t::MAGIC_N = 22643
static

For checking memory corruption.

◆ magic_n

uint32_t rw_lock_t::magic_n = {MAGIC_N}

◆ pfs_psi

struct PSI_rwlock* rw_lock_t::pfs_psi

The instrumentation hook.

◆ reader_thread

Atomic_xor_of_thread_id rw_lock_t::reader_thread

XOR of reader threads' IDs.

If there is exactly one reader it should allow to retrieve the thread ID of that reader.

◆ recursive

std::atomic<bool> rw_lock_t::recursive

Default value false which means the lock is non-recursive.

The value is typically set to true making normal rw_locks recursive. In case of asynchronous IO, when a non-zero value of 'pass' is passed then we keep the lock non-recursive.

This flag also tells us about the state of writer_thread field. If this flag is set then writer_thread MUST contain the thread id of the current x-holder or wait-x thread. This flag must be reset in x_unlock functions before incrementing the lock_word

◆ sx_recursive

std::atomic<uint64_t> rw_lock_t::sx_recursive

number of granted SX locks.

◆ wait_ex_event

os_event_t rw_lock_t::wait_ex_event

Event for next-writer to wait on.

A thread must decrement lock_word before waiting.

◆ waiters

std::atomic<bool> rw_lock_t::waiters

1: there are waiters

◆ writer_thread

std::atomic<std::thread::id> rw_lock_t::writer_thread

Thread id of writer thread.

Is only guaranteed to have non-stale value if recursive flag is set, otherwise it may contain native thread ID of a thread which already released or passed the lock.


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