MySQL  8.0.20
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...
 
virtual ~rw_lock_t ()
 Destructor. More...
 
virtual std::string to_string () const
 Print the rw-lock information. More...
 
virtual std::string locked_from () const
 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

volatile lint lock_word
 Holds the state of the lock. More...
 
volatile ulint waiters
 1: there are waiters More...
 
std::atomic< boolrecursive
 Default value FALSE which means the lock is non-recursive. More...
 
volatile ulint sx_recursive
 number of granted SX locks. 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...
 
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...
 
unsigned cline: 13
 Line where created. More...
 
unsigned is_block_lock: 1
 If 1 then the rw-lock is a block lock. More...
 
unsigned last_s_line: 14
 Line number where last time s-locked. More...
 
unsigned last_x_line: 14
 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...
 
ib_mutex_t mutex
 The mutex protecting rw_lock_t. 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()

virtual rw_lock_t::~rw_lock_t ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ locked_from()

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

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
virtual

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

unsigned 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

unsigned 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

unsigned 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

unsigned 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

volatile lint 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}

◆ mutex

ib_mutex_t rw_lock_t::mutex
mutable

The mutex protecting rw_lock_t.

◆ 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

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