MySQL  8.0.23
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:
latch_t

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
 
 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) debug_list
 In the debug version: pointer to the debug info list of the lock. 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
 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< boolwaiters
 1: there are waiters More...
 
std::atomic< boolrecursive
 Default value FALSE which means the lock is non-recursive. More...
 
bool writer_is_wait_ex
 This is TRUE if the writer field is RW_LOCK_X_WAIT; this field is located far from the memory update hotspot fields which are at the start of this struct, thus we can peek this field without causing much memory bus traffic. More...
 
volatile ulint sx_recursive
 number of granted SX locks. More...
 
std::atomic< os_thread_id_twriter_thread
 Thread id of writer thread. 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...
 
const char * cfile_name
 File name 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...
 
uint16_t cline
 Line where created. 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}
 
latch_level_t level
 Level in the global latching order. More...
 
- 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 ( )
inlineoverride

Destructor.

Member Function Documentation

◆ 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  )

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

◆ cfile_name

const char* rw_lock_t::cfile_name

File name where lock created.

◆ cline

uint16_t rw_lock_t::cline

Line where 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.

◆ level

latch_level_t rw_lock_t::level

Level in the global latching order.

◆ 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.

◆ 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

volatile ulint 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_is_wait_ex

bool rw_lock_t::writer_is_wait_ex

This is TRUE if the writer field is RW_LOCK_X_WAIT; this field is located far from the memory update hotspot fields which are at the start of this struct, thus we can peek this field without causing much memory bus traffic.

◆ writer_thread

std::atomic<os_thread_id_t> 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 handle of a thread which already released or passed the lock.


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