drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
sync0rw.h File Reference
#include "univ.i"
#include "ut0lst.h"
#include "sync0sync.h"
#include "os0sync.h"
Include dependency graph for sync0rw.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rw_lock_struct

Macros

#define sync0rw_h
#define RW_S_LATCH   1
#define RW_X_LATCH   2
#define RW_NO_LATCH   3
#define X_LOCK_DECR   0x00100000
#define rw_lock_create(K, L, level)
#define rw_lock_s_lock(M)
#define rw_lock_s_lock_gen(M, P)
#define rw_lock_s_lock_nowait(M, F, L)
#define rw_lock_s_unlock_gen(L, P)
#define rw_lock_x_lock(M)
#define rw_lock_x_lock_gen(M, P)
#define rw_lock_x_lock_nowait(M)
#define rw_lock_x_unlock_gen(L, P)
#define rw_lock_free(M)
#define rw_lock_s_unlock(L)
#define rw_lock_x_unlock(L)

Typedefs

typedef struct rw_lock_struct rw_lock_t

Functions

typedef UT_LIST_BASE_NODE_T (rw_lock_t) rw_lock_list_t
UNIV_INTERN void rw_lock_create_func (rw_lock_t *lock, const char *cfile_name, ulint cline)
UNIV_INTERN void rw_lock_free_func (rw_lock_t *lock)
UNIV_INLINE ibool rw_lock_s_lock_low (rw_lock_t *lock, ulint, const char *file_name, ulint line)
UNIV_INLINE void rw_lock_s_lock_func (rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
UNIV_INLINE ibool rw_lock_x_lock_func_nowait (rw_lock_t *lock, const char *file_name, ulint line)
UNIV_INLINE void rw_lock_s_unlock_func (rw_lock_t *lock)
UNIV_INTERN void rw_lock_x_lock_func (rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
UNIV_INLINE void rw_lock_x_unlock_func (rw_lock_t *lock)
UNIV_INLINE void rw_lock_s_lock_direct (rw_lock_t *lock, const char *file_name, ulint line)
UNIV_INLINE void rw_lock_x_lock_direct (rw_lock_t *lock, const char *file_name, ulint line)
UNIV_INTERN void rw_lock_x_lock_move_ownership (rw_lock_t *lock)
UNIV_INLINE void rw_lock_s_unlock_direct (rw_lock_t *lock)
UNIV_INLINE void rw_lock_x_unlock_direct (rw_lock_t *lock)
UNIV_INLINE ulint rw_lock_get_x_lock_count (const rw_lock_t *lock)
UNIV_INLINE ulint rw_lock_get_waiters (const rw_lock_t *lock)
UNIV_INLINE ulint rw_lock_get_writer (const rw_lock_t *lock)
UNIV_INLINE ulint rw_lock_get_reader_count (const rw_lock_t *lock)
UNIV_INLINE ibool rw_lock_lock_word_decr (rw_lock_t *lock, ulint amount)
UNIV_INLINE lint rw_lock_lock_word_incr (rw_lock_t *lock, ulint amount)
UNIV_INLINE void rw_lock_set_writer_id_and_recursion_flag (rw_lock_t *lock, ibool recursive)
UNIV_INTERN ibool rw_lock_is_locked (rw_lock_t *lock, ulint lock_type)

Variables

rw_lock_list_t rw_lock_list
mutex_t rw_lock_list_mutex
ib_int64_t rw_s_spin_wait_count
ib_int64_t rw_s_spin_round_count
ib_int64_t rw_s_exit_count
ib_int64_t rw_s_os_wait_count
ib_int64_t rw_x_spin_wait_count
ib_int64_t rw_x_spin_round_count
ib_int64_t rw_x_os_wait_count
ib_int64_t rw_x_exit_count

Detailed Description

The read-write lock (for threads, not for database transactions)

Created 9/11/1995 Heikki Tuuri

Definition in file sync0rw.h.

Macro Definition Documentation

◆ rw_lock_create

#define rw_lock_create ( K,
L,
level )
Value:
rw_lock_create_func((L), __FILE__, __LINE__)
UNIV_INTERN void rw_lock_create_func(rw_lock_t *lock, const char *cfile_name, ulint cline)
Definition sync0rw.cc:238

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. if MySQL performance schema is enabled and "UNIV_PFS_RWLOCK" is defined, the rwlock are instrumented with performance schema probes.

Definition at line 147 of file sync0rw.h.

◆ rw_lock_free

#define rw_lock_free ( M)
Value:
UNIV_INTERN void rw_lock_free_func(rw_lock_t *lock)
Definition sync0rw.cc:314

Definition at line 186 of file sync0rw.h.

◆ rw_lock_s_lock

#define rw_lock_s_lock ( M)
Value:
rw_lock_s_lock_func((M), 0, __FILE__, __LINE__)
UNIV_INLINE void rw_lock_s_lock_func(rw_lock_t *lock, ulint pass, const char *file_name, ulint line)

NOTE! The following macros should be used in rw locking and unlocking, not the corresponding function.

Definition at line 155 of file sync0rw.h.

◆ rw_lock_s_lock_gen

#define rw_lock_s_lock_gen ( M,
P )
Value:
rw_lock_s_lock_func((M), (P), __FILE__, __LINE__)

Definition at line 158 of file sync0rw.h.

◆ rw_lock_s_lock_nowait

#define rw_lock_s_lock_nowait ( M,
F,
L )
Value:
rw_lock_s_lock_low((M), 0, (F), (L))
UNIV_INLINE ibool rw_lock_s_lock_low(rw_lock_t *lock, ulint, const char *file_name, ulint line)

Definition at line 161 of file sync0rw.h.

◆ rw_lock_s_unlock

#define rw_lock_s_unlock ( L)
Value:
rw_lock_s_unlock_gen(L, 0)

Definition at line 242 of file sync0rw.h.

◆ rw_lock_s_unlock_gen

#define rw_lock_s_unlock_gen ( L,
P )
Value:
UNIV_INLINE void rw_lock_s_unlock_func(rw_lock_t *lock)

Definition at line 167 of file sync0rw.h.

◆ rw_lock_x_lock

#define rw_lock_x_lock ( M)
Value:
rw_lock_x_lock_func((M), 0, __FILE__, __LINE__)
UNIV_INTERN void rw_lock_x_lock_func(rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
Definition sync0rw.cc:616

Definition at line 171 of file sync0rw.h.

◆ rw_lock_x_lock_gen

#define rw_lock_x_lock_gen ( M,
P )
Value:
rw_lock_x_lock_func((M), (P), __FILE__, __LINE__)

Definition at line 174 of file sync0rw.h.

◆ rw_lock_x_lock_nowait

#define rw_lock_x_lock_nowait ( M)
Value:
rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__)
UNIV_INLINE ibool rw_lock_x_lock_func_nowait(rw_lock_t *lock, const char *file_name, ulint line)

Definition at line 177 of file sync0rw.h.

◆ rw_lock_x_unlock

#define rw_lock_x_unlock ( L)
Value:
rw_lock_x_unlock_gen(L, 0)

Definition at line 243 of file sync0rw.h.

◆ rw_lock_x_unlock_gen

#define rw_lock_x_unlock_gen ( L,
P )
Value:
UNIV_INLINE void rw_lock_x_unlock_func(rw_lock_t *lock)

Definition at line 183 of file sync0rw.h.

◆ RW_NO_LATCH

#define RW_NO_LATCH   3

Definition at line 52 of file sync0rw.h.

◆ RW_S_LATCH

#define RW_S_LATCH   1

Definition at line 50 of file sync0rw.h.

◆ RW_X_LATCH

#define RW_X_LATCH   2

Definition at line 51 of file sync0rw.h.

◆ sync0rw_h

#define sync0rw_h

Definition at line 35 of file sync0rw.h.

◆ X_LOCK_DECR

#define X_LOCK_DECR   0x00100000

Definition at line 59 of file sync0rw.h.

Typedef Documentation

◆ rw_lock_t

typedef struct rw_lock_struct rw_lock_t

Definition at line 61 of file sync0rw.h.

Function Documentation

◆ rw_lock_create_func()

UNIV_INTERN void rw_lock_create_func ( rw_lock_t * lock,
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. in: file line where created

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
cfile_namein: file name where created
clinein: file line where created

Definition at line 238 of file sync0rw.cc.

◆ rw_lock_free_func()

UNIV_INTERN 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. in: rw-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: rw-lock

Definition at line 314 of file sync0rw.cc.

◆ rw_lock_get_reader_count()

UNIV_INLINE ulint rw_lock_get_reader_count ( const rw_lock_t * lock)

Returns the number of readers.

Returns
number of readers in: rw-lock

◆ rw_lock_get_waiters()

UNIV_INLINE ulint rw_lock_get_waiters ( const rw_lock_t * lock)

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

Returns
1 if waiters, 0 otherwise in: rw-lock

◆ rw_lock_get_writer()

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

Returns
RW_LOCK_NOT_LOCKED, RW_LOCK_EX, RW_LOCK_WAIT_EX in: rw-lock

◆ rw_lock_get_x_lock_count()

UNIV_INLINE ulint rw_lock_get_x_lock_count ( const rw_lock_t * lock)

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 in: rw-lock

◆ rw_lock_is_locked()

UNIV_INTERN ibool rw_lock_is_locked ( rw_lock_t * lock,
ulint lock_type )

Checks if somebody has locked the rw-lock in the specified mode. in: lock type: RW_LOCK_SHARED, RW_LOCK_EX

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_SHARED, RW_LOCK_EX

Definition at line 881 of file sync0rw.cc.

◆ rw_lock_lock_word_decr()

UNIV_INLINE ibool rw_lock_lock_word_decr ( rw_lock_t * lock,
ulint amount )

Decrements lock_word the specified amount if it is greater than 0. This is used by both s_lock and x_lock operations.

Returns
TRUE if decr occurs in: amount to decrement
Parameters
lockin/out: rw-lock

◆ rw_lock_lock_word_incr()

UNIV_INLINE lint rw_lock_lock_word_incr ( rw_lock_t * lock,
ulint amount )

Increments lock_word the specified amount and returns new value.

Returns
lock->lock_word after increment in: amount to increment
Parameters
lockin/out: rw-lock

◆ rw_lock_s_lock_direct()

UNIV_INLINE void rw_lock_s_lock_direct ( rw_lock_t * lock,
const char * file_name,
ulint line )

Low-level function which locks an rw-lock in s-mode when we know that it is possible and none else is currently accessing the rw-lock structure. Then we can do the locking without reserving the mutex. in: line where lock requested

Parameters
lockin/out: rw-lock
file_namein: file name where requested

◆ rw_lock_s_lock_func()

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

NOTE! Use the corresponding macro, not directly this function, except if you supply the file name and line number. 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 SYNC_SPIN_ROUNDS), waiting for the lock, before suspending the thread. in: line where requested

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

◆ rw_lock_s_lock_low()

UNIV_INLINE ibool rw_lock_s_lock_low ( rw_lock_t * lock,
ulint ,
const char * file_name,
ulint line )

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

Returns
TRUE if success in: line where requested
Parameters
lockin: pointer to rw-lock
file_namein: file name where lock requested

◆ rw_lock_s_unlock_direct()

UNIV_INLINE void rw_lock_s_unlock_direct ( rw_lock_t * lock)

Releases a shared mode lock when we know there are no waiters and none else will access the lock during the time this function is executed. in/out: rw-lock

◆ rw_lock_s_unlock_func()

UNIV_INLINE void rw_lock_s_unlock_func ( rw_lock_t * lock)

Releases a shared mode lock. in/out: rw-lock

◆ rw_lock_set_writer_id_and_recursion_flag()

UNIV_INLINE void rw_lock_set_writer_id_and_recursion_flag ( rw_lock_t * lock,
ibool recursive )

This function sets the lock->writer_thread and lock->recursive fields. For platforms where we are using atomic builtins instead of lock->mutex it sets the lock->writer_thread field using atomics to ensure memory ordering. Note that it is assumed that the caller of this function effectively owns the lock i.e.: nobody else is allowed to modify lock->writer_thread at this point in time. The protocol is that lock->writer_thread MUST be updated BEFORE the lock->recursive flag is set. in: TRUE if recursion allowed

Parameters
lockin/out: lock to work on

◆ rw_lock_x_lock_direct()

UNIV_INLINE void rw_lock_x_lock_direct ( rw_lock_t * lock,
const char * file_name,
ulint line )

Low-level function which locks an rw-lock in x-mode when we know that it is not locked and none else is currently accessing the rw-lock structure. Then we can do the locking without reserving the mutex. in: line where lock requested

Parameters
lockin/out: rw-lock
file_namein: file name where requested

◆ rw_lock_x_lock_func()

UNIV_INTERN 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 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 x-lock may be taken on the lock. NOTE: If the same thread has an s-lock, locking does not succeed! in: line where requested

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 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 x-lock may be taken on the lock. NOTE: If the same thread has an s-lock, locking does not succeed!

< index of the reserved wait cell

< spin round count

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

Definition at line 616 of file sync0rw.cc.

◆ rw_lock_x_lock_func_nowait()

UNIV_INLINE ibool rw_lock_x_lock_func_nowait ( rw_lock_t * lock,
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 lock can be obtained immediately.

Returns
TRUE if success in: line where requested
Parameters
lockin: pointer to rw-lock
file_namein: file name where lock requested

◆ rw_lock_x_lock_move_ownership()

UNIV_INTERN 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. in: lock which was x-locked in the buffer read

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

Definition at line 473 of file sync0rw.cc.

◆ rw_lock_x_unlock_direct()

UNIV_INLINE void rw_lock_x_unlock_direct ( rw_lock_t * lock)

Releases an exclusive mode lock when we know there are no waiters, and none else will access the lock durint the time this function is executed. in/out: rw-lock

◆ rw_lock_x_unlock_func()

UNIV_INLINE void rw_lock_x_unlock_func ( rw_lock_t * lock)

Releases an exclusive mode lock. in/out: rw-lock

Variable Documentation

◆ rw_lock_list

rw_lock_list_t rw_lock_list
extern

Definition at line 169 of file sync0rw.cc.

◆ rw_lock_list_mutex

mutex_t rw_lock_list_mutex
extern

Definition at line 170 of file sync0rw.cc.

◆ rw_s_exit_count

ib_int64_t rw_s_exit_count
extern

number of unlocks (that unlock shared locks), set only when UNIV_SYNC_PERF_STAT is defined

Definition at line 151 of file sync0rw.cc.

◆ rw_s_os_wait_count

ib_int64_t rw_s_os_wait_count
extern

number of OS waits on rw-latches, resulted during shared (read) locks

Definition at line 147 of file sync0rw.cc.

◆ rw_s_spin_round_count

ib_int64_t rw_s_spin_round_count
extern

number of spin loop rounds on rw-latches, resulted during exclusive (write) locks

number of spin loop rounds on rw-latches, resulted during shared (read) locks

Definition at line 143 of file sync0rw.cc.

◆ rw_s_spin_wait_count

ib_int64_t rw_s_spin_wait_count
extern

number of spin waits on rw-latches, resulted during exclusive (write) locks

number of spin waits on rw-latches, resulted during shared (read) locks

Definition at line 140 of file sync0rw.cc.

◆ rw_x_exit_count

ib_int64_t rw_x_exit_count
extern

number of unlocks (that unlock exclusive locks), set only when UNIV_SYNC_PERF_STAT is defined

Definition at line 166 of file sync0rw.cc.

◆ rw_x_os_wait_count

ib_int64_t rw_x_os_wait_count
extern

number of OS waits on rw-latches, resulted during exclusive (write) locks

Definition at line 162 of file sync0rw.cc.

◆ rw_x_spin_round_count

ib_int64_t rw_x_spin_round_count
extern

number of spin loop rounds on rw-latches, resulted during shared (read) locks

number of spin loop rounds on rw-latches, resulted during exclusive (write) locks

Definition at line 158 of file sync0rw.cc.

◆ rw_x_spin_wait_count

ib_int64_t rw_x_spin_wait_count
extern

number of spin waits on rw-latches, resulted during shared (read) locks

number of spin waits on rw-latches, resulted during exclusive (write) locks

Definition at line 155 of file sync0rw.cc.