MySQL  8.0.23
Source Code Documentation
sync0rw.cc File Reference
#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"

Macros

#define rw_lock_x_lock_wait(L, P, T, F, O)   rw_lock_x_lock_wait_func(L, P, T, F, O)
 

Typedefs

typedef std::vector< 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_level_t level, const char *cmutex_name, const char *cfile_name, ulint cline)
 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, const char *file_name, ulint line)
 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...
 
UNIV_INLINE 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...
 
UNIV_INLINE 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, const char *file_name, ulint line)
 Low-level function for acquiring an sx lock. More...
 
void rw_lock_x_lock_func (rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
 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, const char *file_name, ulint line)
 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, const char *file_name, ulint line)
 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...
 
ibool rw_lock_own (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_stats_t rw_lock_stats
 Counters for RW locks. More...
 
rw_lock_list_t rw_lock_list
 
ib_mutex_t rw_lock_list_mutex
 

Detailed Description

The read-write lock (for thread synchronization)

Created 9/11/1995 Heikki Tuuri

Macro Definition Documentation

◆ rw_lock_x_lock_wait

#define rw_lock_x_lock_wait (   L,
  P,
  T,
  F,
 
)    rw_lock_x_lock_wait_func(L, P, T, F, O)

Typedef Documentation

◆ Infos

typedef std::vector<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,
const char *  file_name,
ulint  line 
)

Inserts the debug information for an rw-lock.

Parameters
lockin: rw-lock
passin: pass value
lock_typein: lock type
file_namein: file where requested
linein: line where requested

◆ rw_lock_create_func()

void rw_lock_create_func ( rw_lock_t lock,
latch_level_t  level,
const char *  cmutex_name,
const char *  cfile_name,
ulint  cline 
)

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
lockin: pointer to memory
levelin: level
cmutex_namein: rw-lock name
cfile_namein: file name where created
clinein: file line 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
Returns
the thread debug info or NULL if not found

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

in: file where to print

Parameters
filein: file where to print

◆ rw_lock_own()

ibool rw_lock_own ( 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.

Returns
true if locked
Parameters
lockin: rw-lock
lock_typein: lock type: RW_LOCK_S, 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.

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,
const char *  file_name,
ulint  line 
)

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
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_sx_lock_func()

void rw_lock_sx_lock_func ( rw_lock_t lock,
ulint  pass,
const char *  file_name,
ulint  line 
)

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
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_sx_lock_low()

bool rw_lock_sx_lock_low ( rw_lock_t lock,
ulint  pass,
const char *  file_name,
ulint  line 
)

Low-level function for acquiring an sx 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_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,
const char *  file_name,
ulint  line 
)

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
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_low()

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

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_func()

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

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

Parameters
lockin: pointer to rw-lock
passin: pass value; != 0, if the lock will be passed to another thread to unlock
thresholdin: threshold to wait for
file_namein: file name where lock requested
linein: line where requested

Variable Documentation

◆ rw_lock_list

rw_lock_list_t rw_lock_list

◆ rw_lock_list_mutex

ib_mutex_t rw_lock_list_mutex

◆ rw_lock_stats

rw_lock_stats_t rw_lock_stats

Counters for RW locks.