MySQL 9.0.0
Source Code Documentation
sync0rw.cc File Reference

The read-write lock (for thread synchronization) More...

#include "sync0rw.h"
#include <my_sys.h>
#include <sys/types.h>
#include "ha_prototypes.h"
#include "mem0mem.h"
#include "os0event.h"
#include "os0thread.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "sync0debug.h"

Typedefs

typedef std::vector< const rw_lock_debug_t * > Infos
 For collecting the debug information for a thread's rw-lock. More...
 

Functions

static rw_lock_debug_trw_lock_debug_create (void)
 Creates a debug info struct. More...
 
static void rw_lock_debug_free (rw_lock_debug_t *info)
 Frees a debug info struct. More...
 
void rw_lock_create_func (rw_lock_t *lock, latch_id_t id, ut::Location clocation)
 Creates, or rather, initializes an rw-lock object in a specified memory location (which must be appropriately aligned). More...
 
void rw_lock_free_func (rw_lock_t *lock)
 Calling this function is obligatory only if the memory buffer containing the rw-lock is freed. More...
 
void rw_lock_s_lock_spin (rw_lock_t *lock, ulint pass, ut::Location location)
 Lock an rw-lock in shared mode for the current thread. More...
 
void rw_lock_x_lock_move_ownership (rw_lock_t *lock)
 This function is used in the insert buffer to move the ownership of an x-latch on a buffer frame to the current thread. More...
 
static void rw_lock_x_lock_wait_func (rw_lock_t *lock, ulint pass, lint threshold, const char *file_name, ulint line)
 Function for the next writer to call. More...
 
static void rw_lock_x_lock_wait (rw_lock_t *lock, ulint pass, lint treshold, const char *file_name, ulint line)
 Function for the next writer to call. More...
 
static bool rw_lock_x_lock_low (rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
 Low-level function for acquiring an exclusive lock. More...
 
bool rw_lock_sx_lock_low (rw_lock_t *lock, ulint pass, ut::Location location)
 Low-level function for acquiring an sx lock. More...
 
void rw_lock_x_lock_func (rw_lock_t *lock, ulint pass, ut::Location location)
 NOTE! Use the corresponding macro, not directly this function! Lock an rw-lock in exclusive mode for the current thread. More...
 
void rw_lock_sx_lock_func (rw_lock_t *lock, ulint pass, ut::Location location)
 NOTE! Use the corresponding macro, not directly this function! Lock an rw-lock in SX mode for the current thread. More...
 
bool rw_lock_validate (const rw_lock_t *lock)
 Checks that the rw-lock has been initialized and that there are no simultaneous shared and exclusive locks. More...
 
bool rw_lock_is_locked (rw_lock_t *lock, ulint lock_type)
 Checks if somebody has locked the rw-lock in the specified mode. More...
 
void rw_lock_add_debug_info (rw_lock_t *lock, ulint pass, ulint lock_type, ut::Location location)
 Inserts the debug information for an rw-lock. More...
 
void rw_lock_remove_debug_info (rw_lock_t *lock, ulint pass, ulint lock_type)
 Removes a debug information struct for an rw-lock. More...
 
bool rw_lock_own (const rw_lock_t *lock, ulint lock_type)
 Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0. More...
 
static void rw_lock_get_debug_info (const rw_lock_t *lock, Infos *infos)
 Get the thread debug info. More...
 
bool rw_lock_own_flagged (const rw_lock_t *lock, rw_lock_flags_t flags)
 Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0. More...
 
void rw_lock_list_print_info (FILE *file)
 Prints debug info of currently locked rw-locks. More...
 
void rw_lock_debug_print (FILE *f, const rw_lock_debug_t *info)
 Prints info of a debug struct. More...
 

Variables

rw_lock_list_t rw_lock_list {}
 The global list of rw-locks. More...
 
ib_mutex_t rw_lock_list_mutex
 

Detailed Description

The read-write lock (for thread synchronization)

Created 9/11/1995 Heikki Tuuri

Typedef Documentation

◆ Infos

typedef std::vector<const rw_lock_debug_t *> Infos

For collecting the debug information for a thread's rw-lock.

Function Documentation

◆ rw_lock_add_debug_info()

void rw_lock_add_debug_info ( rw_lock_t lock,
ulint  pass,
ulint  lock_type,
ut::Location  location 
)

Inserts the debug information for an rw-lock.

Parameters
[in]lockrw-lock
[in]passpass value
[in]lock_typelock type
[in]locationlocation where requested

◆ rw_lock_create_func()

void rw_lock_create_func ( rw_lock_t lock,
latch_id_t  id,
ut::Location  clocation 
)

Creates, or rather, initializes an rw-lock object in a specified memory location (which must be appropriately aligned).

The rw-lock is initialized to the non-locked state. Explicit freeing of the rw-lock with rw_lock_free is necessary only if the memory block containing it is freed.

Parameters
[in]lockpointer to memory
[in]idlatch_id
[in]clocationlocation where created

◆ rw_lock_debug_create()

static rw_lock_debug_t * rw_lock_debug_create ( void  )
static

Creates a debug info struct.

Returns
own: debug info struct

◆ rw_lock_debug_free()

static void rw_lock_debug_free ( rw_lock_debug_t info)
static

Frees a debug info struct.

◆ rw_lock_debug_print()

void rw_lock_debug_print ( FILE *  f,
const rw_lock_debug_t info 
)

Prints info of a debug struct.

Parameters
[in]fOutput stream
[in]infoDebug struct

◆ rw_lock_free_func()

void rw_lock_free_func ( rw_lock_t lock)

Calling this function is obligatory only if the memory buffer containing the rw-lock is freed.

Removes an rw-lock object from the global list. The rw-lock is checked to be in the non-locked state.

Parameters
lockin/out: rw-lock

◆ rw_lock_get_debug_info()

static void rw_lock_get_debug_info ( const rw_lock_t lock,
Infos infos 
)
static

Get the thread debug info.

Parameters
[in]infosThe rw-lock mode owned by the threads
[in]lockrw-lock to check

◆ rw_lock_is_locked()

bool rw_lock_is_locked ( rw_lock_t lock,
ulint  lock_type 
)

Checks if somebody has locked the rw-lock in the specified mode.

Returns
true if locked
Parameters
lockin: rw-lock
lock_typein: lock type: RW_LOCK_S, RW_LOCK_X or RW_LOCK_SX

◆ rw_lock_list_print_info()

void rw_lock_list_print_info ( FILE *  file)

Prints debug info of currently locked rw-locks.

Parameters
[in]filefile where to print
Parameters
filein: file where to print

◆ rw_lock_own()

bool rw_lock_own ( const rw_lock_t lock,
ulint  lock_type 
)

Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0.

Note that the mode is checked exactly, so if the thread owns RW_LOCK_X only, the rw_lock_own(..,RW_LOCK_S) will return false.

Parameters
[in]lockthe rw-lock
[in]lock_typeThe exact lock type to check: RW_LOCK_S, RW_LOCK_SX or RW_LOCK_X

◆ rw_lock_own_flagged()

bool rw_lock_own_flagged ( const rw_lock_t lock,
rw_lock_flags_t  flags 
)

Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0.

Parameters
[in]lockrw-lock
[in]flagsspecify lock types with OR of the rw_lock_flag_t values
Returns
true if locked

◆ rw_lock_remove_debug_info()

void rw_lock_remove_debug_info ( rw_lock_t lock,
ulint  pass,
ulint  lock_type 
)

Removes a debug information struct for an rw-lock.

in: lock type

Parameters
lockin: rw-lock
passin: pass value
lock_typein: lock type

◆ rw_lock_s_lock_spin()

void rw_lock_s_lock_spin ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)

Lock an rw-lock in shared mode for the current thread.

If the rw-lock is locked in exclusive mode, or there is an exclusive lock request waiting, the function spins a preset time (controlled by srv_n_spin_wait_rounds), waiting for the lock before suspending the thread.

Parameters
[in]lockpointer to rw-lock
[in]passpass value; !=0, if the lock will be passed to another thread to unlock
[in]locationlocation where requested

◆ rw_lock_sx_lock_func()

void rw_lock_sx_lock_func ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)

NOTE! Use the corresponding macro, not directly this function! Lock an rw-lock in SX mode for the current thread.

If the rw-lock is locked in exclusive mode, or there is an exclusive lock request waiting, the function spins a preset time (controlled by SYNC_SPIN_ROUNDS), waiting for the lock, before suspending the thread. If the same thread has an x-lock on the rw-lock, locking succeed, with the following exception: if pass != 0, only a single sx-lock may be taken on the lock. NOTE: If the same thread has an s-lock, locking does not succeed!

Parameters
[in]lockpointer to rw-lock
[in]passpass value; != 0, if the lock will be passed to another thread to unlock
[in]locationlocation where requested

◆ rw_lock_sx_lock_low()

bool rw_lock_sx_lock_low ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)

Low-level function for acquiring an sx lock.

Parameters
[in]lockpointer to rw-lock
[in]passpass value; != 0, if the lock will be passed to another thread to unlock
[in]locationlocation where requested
Returns
false if did not succeed, true if success.

◆ rw_lock_validate()

bool rw_lock_validate ( const rw_lock_t lock)

Checks that the rw-lock has been initialized and that there are no simultaneous shared and exclusive locks.

Returns
true
Parameters
lockin: rw-lock

◆ rw_lock_x_lock_func()

void rw_lock_x_lock_func ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)

NOTE! Use the corresponding macro, not directly this function! Lock an rw-lock in exclusive mode for the current thread.

If the rw-lock is locked in shared or exclusive mode, or there is an exclusive lock request waiting, the function spins a preset time (controlled by srv_n_spin_wait_rounds), waiting for the lock, before suspending the thread. If the same thread has an x-lock on the rw-lock, locking succeed, with the following exception: if pass != 0, only a single x-lock may be taken on the lock. NOTE: If the same thread has an s-lock, locking does not succeed!

Parameters
[in]lockpointer to rw-lock
[in]passpass value; != 0, if the lock will be passed to another thread to unlock
[in]locationlocation where requested

◆ rw_lock_x_lock_low()

static bool rw_lock_x_lock_low ( rw_lock_t lock,
ulint  pass,
const char *  file_name,
ulint  line 
)
inlinestatic

Low-level function for acquiring an exclusive lock.

Returns
false if did not succeed, true if success.
Parameters
lockin: pointer to rw-lock
passin: pass value; != 0, if the lock will be passed to another thread to unlock
file_namein: file name where lock requested
linein: line where requested

◆ rw_lock_x_lock_move_ownership()

void rw_lock_x_lock_move_ownership ( rw_lock_t lock)

This function is used in the insert buffer to move the ownership of an x-latch on a buffer frame to the current thread.

The x-latch was set by the buffer read operation and it protected the buffer frame while the read was done. The ownership is moved because we want that the current thread is able to acquire a second x-latch which is stored in an mtr. This, in turn, is needed to pass the debug checks of index page operations.

Parameters
lockin: lock which was x-locked in the buffer read

◆ rw_lock_x_lock_wait()

static void rw_lock_x_lock_wait ( rw_lock_t lock,
ulint  pass,
lint  treshold,
const char *  file_name,
ulint  line 
)
inlinestatic

Function for the next writer to call.

Waits for readers to exit. The caller must have already decremented lock_word by X_LOCK_DECR.

Parameters
[in]lockpointer to rw-lock
[in]passpass value; != 0, if the lock will be passed to another thread to unlock
[in]tresholdthreshold to wait for
[in]file_namefile name where lock requested
[in]lineline where requested

◆ rw_lock_x_lock_wait_func()

static void rw_lock_x_lock_wait_func ( rw_lock_t lock,
ulint  pass,
lint  threshold,
const char *  file_name,
ulint  line 
)
inlinestatic

Function for the next writer to call.

Waits for readers to exit. The caller must have already decremented lock_word by X_LOCK_DECR.

Parameters
[in]lockpointer to rw-lock
[in]passpass value; != 0, if the lock will be passed to another thread to unlock
[in]thresholdthreshold to wait for
[in]file_namefile name where lock requested
[in]lineline where requested

Variable Documentation

◆ rw_lock_list

rw_lock_list_t rw_lock_list {}

The global list of rw-locks.

◆ rw_lock_list_mutex

ib_mutex_t rw_lock_list_mutex