MySQL 8.0.31
Source Code Documentation
sync0rw.ic File Reference

The read-write lock (for threads) More...

#include "os0event.h"

Functions

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_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...
 
static bool rw_lock_get_waiters (const rw_lock_t *lock)
 Check if there are threads waiting for the rw-lock. More...
 
static void rw_lock_set_waiter_flag (rw_lock_t *lock)
 Sets lock->waiters to true. More...
 
static void rw_lock_reset_waiter_flag (rw_lock_t *lock)
 Resets lock->waiters to false. More...
 
static ulint rw_lock_get_writer (const rw_lock_t *lock)
 Returns the write-status of the lock - this function made more sense with the old rw_lock implementation. More...
 
static ulint rw_lock_get_reader_count (const rw_lock_t *lock)
 Returns the number of readers (s-locks). More...
 
static ulint rw_lock_get_x_lock_count (const rw_lock_t *lock)
 Returns the value of writer_count for the lock. More...
 
static ulint rw_lock_get_sx_lock_count (const rw_lock_t *lock)
 Returns the number of sx-lock for the lock. More...
 
ALWAYS_INLINE bool rw_lock_lock_word_decr (rw_lock_t *lock, ulint amount, lint threshold)
 Two different implementations for decrementing the lock_word of a rw_lock: one for systems supporting atomic operations, one for others. More...
 
static lint rw_lock_lock_word_incr (rw_lock_t *lock, ulint amount)
 Increments lock_word the specified amount and returns new value. More...
 
static void rw_lock_set_writer_id_and_recursion_flag (rw_lock_t *lock, bool recursive)
 
ALWAYS_INLINE bool rw_lock_s_lock_low (rw_lock_t *lock, ulint pass, ut::Location location)
 Low-level function which tries to lock an rw-lock in s-mode. More...
 
static void rw_lock_s_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 shared mode for the current thread. More...
 
static bool rw_lock_x_lock_func_nowait (rw_lock_t *lock, 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 lock can be obtained immediately. More...
 
static void rw_lock_s_unlock_func (ulint pass, rw_lock_t *lock)
 Releases a shared mode lock. More...
 
static void rw_lock_x_unlock_func (ulint pass, rw_lock_t *lock)
 Releases an exclusive mode lock. More...
 
static void rw_lock_sx_unlock_func (ulint pass, rw_lock_t *lock)
 Releases a sx mode lock. More...
 
static void pfs_rw_lock_create_func (mysql_pfs_key_t key, rw_lock_t *lock, latch_level_t level, const char *cmutex_name, ut::Location clocation)
 
static void pfs_rw_lock_x_lock_func (rw_lock_t *lock, ulint pass, ut::Location location)
 Performance schema instrumented wrap function for rw_lock_x_lock_func() NOTE! Please use the corresponding macro rw_lock_x_lock(), not directly this function! More...
 
static bool pfs_rw_lock_x_lock_func_nowait (rw_lock_t *lock, ut::Location location)
 Performance schema instrumented wrap function for rw_lock_x_lock_func_nowait() NOTE! Please use the corresponding macro rw_lock_x_lock_func(), not directly this function! More...
 
static void pfs_rw_lock_free_func (rw_lock_t *lock)
 Performance schema instrumented wrap function for rw_lock_free_func() NOTE! Please use the corresponding macro rw_lock_free(), not directly this function! More...
 
ALWAYS_INLINE void pfs_rw_lock_s_lock_func (rw_lock_t *lock, ulint pass, ut::Location location)
 Performance schema instrumented wrap function for rw_lock_s_lock_func() NOTE! Please use the corresponding macro rw_lock_s_lock(), not directly this function! More...
 
static void pfs_rw_lock_sx_lock_func (rw_lock_t *lock, ulint pass, ut::Location location)
 Performance schema instrumented wrap function for rw_lock_sx_lock_func() NOTE! Please use the corresponding macro rw_lock_sx_lock(), not directly this function! More...
 
static bool pfs_rw_lock_s_lock_low (rw_lock_t *lock, ulint pass, ut::Location location)
 
static bool pfs_rw_lock_sx_lock_low (rw_lock_t *lock, ulint pass, ut::Location location)
 Performance schema instrumented wrap function for rw_lock_sx_lock_nowait() NOTE! Please use the corresponding macro, not directly this function! More...
 
static void pfs_rw_lock_x_unlock_func (ulint pass, rw_lock_t *lock)
 Performance schema instrumented wrap function for rw_lock_x_unlock_func() NOTE! Please use the corresponding macro rw_lock_x_unlock(), not directly this function! More...
 
static void pfs_rw_lock_sx_unlock_func (ulint pass, rw_lock_t *lock)
 
ALWAYS_INLINE void pfs_rw_lock_s_unlock_func (ulint pass, rw_lock_t *lock)
 Performance schema instrumented wrap function for rw_lock_s_unlock_func() NOTE! Please use the corresponding macro rw_lock_s_unlock(), not directly this function! More...
 

Detailed Description

The read-write lock (for threads)

Created 9/11/1995 Heikki Tuuri

Function Documentation

◆ pfs_rw_lock_create_func()

static void pfs_rw_lock_create_func ( mysql_pfs_key_t  key,
rw_lock_t lock,
latch_level_t  level,
const char *  cmutex_name,
ut::Location  clocation 
)
inlinestatic

◆ pfs_rw_lock_free_func()

static void pfs_rw_lock_free_func ( rw_lock_t lock)
inlinestatic

Performance schema instrumented wrap function for rw_lock_free_func() NOTE! Please use the corresponding macro rw_lock_free(), not directly this function!

Parameters
lockin: pointer to rw-lock

◆ pfs_rw_lock_s_lock_func()

ALWAYS_INLINE void pfs_rw_lock_s_lock_func ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inline

Performance schema instrumented wrap function for rw_lock_s_lock_func() NOTE! Please use the corresponding macro rw_lock_s_lock(), not directly this function!

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

◆ pfs_rw_lock_s_lock_low()

static bool pfs_rw_lock_s_lock_low ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inlinestatic

◆ pfs_rw_lock_s_unlock_func()

ALWAYS_INLINE void pfs_rw_lock_s_unlock_func ( ulint  pass,
rw_lock_t lock 
)
inline

Performance schema instrumented wrap function for rw_lock_s_unlock_func() NOTE! Please use the corresponding macro rw_lock_s_unlock(), not directly this function!

Parameters
[in]passpass value; != 0, if the lock may have been passed to another thread to unlock
[in,out]lockrw-lock

◆ pfs_rw_lock_sx_lock_func()

static void pfs_rw_lock_sx_lock_func ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inlinestatic

Performance schema instrumented wrap function for rw_lock_sx_lock_func() NOTE! Please use the corresponding macro rw_lock_sx_lock(), not directly this function!

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

◆ pfs_rw_lock_sx_lock_low()

static bool pfs_rw_lock_sx_lock_low ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inlinestatic

Performance schema instrumented wrap function for rw_lock_sx_lock_nowait() NOTE! Please use the corresponding macro, not directly this function!

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

◆ pfs_rw_lock_sx_unlock_func()

static void pfs_rw_lock_sx_unlock_func ( ulint  pass,
rw_lock_t lock 
)
inlinestatic

◆ pfs_rw_lock_x_lock_func()

static void pfs_rw_lock_x_lock_func ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inlinestatic

Performance schema instrumented wrap function for rw_lock_x_lock_func() NOTE! Please use the corresponding macro rw_lock_x_lock(), not directly this function!

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

◆ pfs_rw_lock_x_lock_func_nowait()

static bool pfs_rw_lock_x_lock_func_nowait ( rw_lock_t lock,
ut::Location  location 
)
inlinestatic

Performance schema instrumented wrap function for rw_lock_x_lock_func_nowait() NOTE! Please use the corresponding macro rw_lock_x_lock_func(), not directly this function!

Returns
true if success
Parameters
lockin: pointer to rw-lock
locationin: line where requested

◆ pfs_rw_lock_x_unlock_func()

static void pfs_rw_lock_x_unlock_func ( ulint  pass,
rw_lock_t lock 
)
inlinestatic

Performance schema instrumented wrap function for rw_lock_x_unlock_func() NOTE! Please use the corresponding macro rw_lock_x_unlock(), not directly this function!

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

static ulint rw_lock_get_reader_count ( const rw_lock_t lock)
inlinestatic

Returns the number of readers (s-locks).

Returns
number of readers
Parameters
lockin: rw-lock

◆ rw_lock_get_sx_lock_count()

static ulint rw_lock_get_sx_lock_count ( const rw_lock_t lock)
inlinestatic

Returns the number of sx-lock for the lock.

Does not reserve the lock mutex, so the caller must be sure it is not changed during the call.

Returns
value of sx-lock count
Parameters
lockin: rw-lock

◆ rw_lock_get_waiters()

static bool rw_lock_get_waiters ( const rw_lock_t lock)
inlinestatic

Check if there are threads waiting for the rw-lock.

Returns
true if waiters, false otherwise
Parameters
lockin: rw-lock

◆ rw_lock_get_writer()

static ulint rw_lock_get_writer ( const rw_lock_t lock)
inlinestatic

Returns the write-status of the lock - this function made more sense with the old rw_lock implementation.

Returns
RW_LOCK_NOT_LOCKED, RW_LOCK_X, RW_LOCK_X_WAIT, RW_LOCK_SX
Parameters
lockin: rw-lock

◆ rw_lock_get_x_lock_count()

static ulint rw_lock_get_x_lock_count ( const rw_lock_t lock)
inlinestatic

Returns the value of writer_count for the lock.

Does not reserve the lock mutex, so the caller must be sure it is not changed during the call.

Returns
value of writer_count
Parameters
lockin: rw-lock

◆ rw_lock_lock_word_decr()

ALWAYS_INLINE bool rw_lock_lock_word_decr ( rw_lock_t lock,
ulint  amount,
lint  threshold 
)
inline

Two different implementations for decrementing the lock_word of a rw_lock: one for systems supporting atomic operations, one for others.

Decrements lock_word the specified amount if it is greater than 0.

This does does not support recursive x-locks: they should be handled by the caller and need not be atomic since they are performed by the current lock holder. Returns true if the decrement was made, false if not.

Returns
true if decr occurs
Parameters
lockin/out: rw-lock
amountin: amount to decrement
thresholdin: threshold of judgement

◆ rw_lock_lock_word_incr()

static lint rw_lock_lock_word_incr ( rw_lock_t lock,
ulint  amount 
)
inlinestatic

Increments lock_word the specified amount and returns new value.

Returns
lock->lock_word after increment
Parameters
lockin/out: rw-lock
amountin: amount of increment

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

static void rw_lock_reset_waiter_flag ( rw_lock_t lock)
inlinestatic

Resets lock->waiters to false.

It is not an error if lock->waiters is already false.

Parameters
lockin/out: rw-lock

◆ rw_lock_s_lock_func()

static void rw_lock_s_lock_func ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inlinestatic

NOTE! Use the corresponding macro, not directly this function! 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_s_lock_low()

ALWAYS_INLINE bool rw_lock_s_lock_low ( rw_lock_t lock,
ulint  pass,
ut::Location  location 
)
inline

Low-level function which tries to lock an rw-lock in s-mode.

Performs no spinning.

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
true if success

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

static void rw_lock_s_unlock_func ( ulint  pass,
rw_lock_t lock 
)
inlinestatic

Releases a shared mode lock.

Parameters
[in]passpass value; != 0, if the lock may have been passed to another thread to unlock
[in,out]lockrw-lock

◆ rw_lock_set_waiter_flag()

static void rw_lock_set_waiter_flag ( rw_lock_t lock)
inlinestatic

Sets lock->waiters to true.

It is not an error if lock->waiters is already true.

Parameters
lockin/out: rw-lock

◆ rw_lock_set_writer_id_and_recursion_flag()

static void rw_lock_set_writer_id_and_recursion_flag ( rw_lock_t lock,
bool  recursive 
)
inlinestatic

◆ rw_lock_sx_unlock_func()

static void rw_lock_sx_unlock_func ( ulint  pass,
rw_lock_t lock 
)
inlinestatic

Releases a sx mode lock.

Parameters
[in]passpass value; != 0, if the lock may have been passed to another thread to unlock
[in,out]lockrw-lock

◆ rw_lock_x_lock_func_nowait()

static bool rw_lock_x_lock_func_nowait ( rw_lock_t lock,
ut::Location  location 
)
inlinestatic

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

Parameters
[in]lockpointer to rw-lock
[in]locationlocation where requested
Returns
true if success

◆ rw_lock_x_unlock_func()

static void rw_lock_x_unlock_func ( ulint  pass,
rw_lock_t lock 
)
inlinestatic

Releases an exclusive mode lock.

Parameters
[in]passpass value; != 0, if the lock may have been passed to another thread to unlock
[in,out]locklock rw-lock