📄 sync0rw.h
字号:
#else#define rw_lock_x_unlock_gen(L, P) rw_lock_x_unlock_func(L)#endif/**********************************************************************Low-level function which locks an rw-lock in s-mode when we know that itis possible and none else is currently accessing the rw-lock structure.Then we can do the locking without reserving the mutex. */UNIV_INLINEvoidrw_lock_s_lock_direct(/*==================*/ rw_lock_t* lock, /* in: pointer to rw-lock */ const char* file_name, /* in: file name where requested */ ulint line /* in: line where lock requested */);/**********************************************************************Low-level function which locks an rw-lock in x-mode when we know that itis not locked and none else is currently accessing the rw-lock structure.Then we can do the locking without reserving the mutex. */UNIV_INLINEvoidrw_lock_x_lock_direct(/*==================*/ rw_lock_t* lock, /* in: pointer to rw-lock */ const char* file_name, /* in: file name where requested */ ulint line /* in: line where lock requested */);/**********************************************************************This function is used in the insert buffer to move the ownership of anx-latch on a buffer frame to the current thread. The x-latch was set bythe buffer read operation and it protected the buffer frame while theread was done. The ownership is moved because we want that the currentthread 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 pageoperations. */voidrw_lock_x_lock_move_ownership(/*==========================*/ rw_lock_t* lock); /* in: lock which was x-locked in the buffer read *//**********************************************************************Releases a shared mode lock when we know there are no waiters and noneelse will access the lock during the time this function is executed. */UNIV_INLINEvoidrw_lock_s_unlock_direct(/*====================*/ rw_lock_t* lock); /* in: rw-lock *//**********************************************************************Releases an exclusive mode lock when we know there are no waiters, andnone else will access the lock durint the time this function is executed. */UNIV_INLINEvoidrw_lock_x_unlock_direct(/*====================*/ rw_lock_t* lock); /* in: rw-lock *//**********************************************************************Sets the rw-lock latching level field. */voidrw_lock_set_level(/*==============*/ rw_lock_t* lock, /* in: rw-lock */ ulint level); /* in: level *//**********************************************************************Returns the value of writer_count for the lock. Does not reserve the lockmutex, so the caller must be sure it is not changed during the call. */UNIV_INLINEulintrw_lock_get_x_lock_count(/*=====================*/ /* out: value of writer_count */ rw_lock_t* lock); /* in: rw-lock *//************************************************************************Accessor functions for rw lock. */UNIV_INLINEulintrw_lock_get_waiters(/*================*/ rw_lock_t* lock);UNIV_INLINEulintrw_lock_get_writer(/*===============*/ rw_lock_t* lock);UNIV_INLINEulintrw_lock_get_reader_count(/*=====================*/ rw_lock_t* lock);#ifdef UNIV_SYNC_DEBUG/**********************************************************************Checks if the thread has locked the rw-lock in the specified mode, withthe pass value == 0. */iboolrw_lock_own(/*========*/ rw_lock_t* lock, /* in: rw-lock */ ulint lock_type); /* in: lock type: RW_LOCK_SHARED, RW_LOCK_EX */#endif /* UNIV_SYNC_DEBUG *//**********************************************************************Checks if somebody has locked the rw-lock in the specified mode. */iboolrw_lock_is_locked(/*==============*/ rw_lock_t* lock, /* in: rw-lock */ ulint lock_type); /* in: lock type: RW_LOCK_SHARED, RW_LOCK_EX */#ifdef UNIV_SYNC_DEBUG/*******************************************************************Prints debug info of an rw-lock. */voidrw_lock_print(/*==========*/ rw_lock_t* lock); /* in: rw-lock *//*******************************************************************Prints debug info of currently locked rw-locks. */voidrw_lock_list_print_info(void);/*=========================*//*******************************************************************Returns the number of currently locked rw-locks.Works only in the debug version. */ulintrw_lock_n_locked(void);/*==================*//*#####################################################################*//**********************************************************************Acquires the debug mutex. We cannot use the mutex defined in sync0sync,because the debug mutex is also acquired in sync0arr while holding the OSmutex protecting the sync array, and the ordinary mutex_enter mightrecursively call routines in sync0arr, leading to a deadlock on the OSmutex. */voidrw_lock_debug_mutex_enter(void);/*==========================*//**********************************************************************Releases the debug mutex. */voidrw_lock_debug_mutex_exit(void);/*==========================*//*************************************************************************Prints info of a debug struct. */voidrw_lock_debug_print(/*================*/ rw_lock_debug_t* info); /* in: debug struct */#endif /* UNIV_SYNC_DEBUG *//* NOTE! The structure appears here only for the compiler to know its size.Do not use its fields directly! The structure used in the spin lockimplementation of a read-write lock. Several threads may have a shared locksimultaneously 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 writerblocked by readers, a writer may queue for the lock by setting the writerfield. Then no new readers are allowed in. */struct rw_lock_struct { ulint reader_count; /* Number of readers who have locked this lock in the shared mode */ ulint writer; /* This field is set to RW_LOCK_EX if there is a writer owning the lock (in exclusive mode), RW_LOCK_WAIT_EX if a writer is queueing for the lock, and RW_LOCK_NOT_LOCKED, otherwise. */ os_thread_id_t writer_thread; /* Thread id of a possible writer thread */ ulint writer_count; /* Number of times the same thread has recursively locked the lock in the exclusive mode */ mutex_t mutex; /* The mutex protecting rw_lock_struct */ ulint pass; /* Default value 0. This is set to some value != 0 given by the caller of an x-lock operation, if the x-lock is to be passed to another thread to unlock (which happens in asynchronous i/o). */ ulint waiters; /* This ulint is set to 1 if there are waiters (readers or writers) in the global wait array, waiting for this rw_lock. Otherwise, == 0. */ ibool writer_is_wait_ex; /* This is TRUE if the writer field is RW_LOCK_WAIT_EX; 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 */ UT_LIST_NODE_T(rw_lock_t) list; /* All allocated rw locks are put into a list */#ifdef UNIV_SYNC_DEBUG UT_LIST_BASE_NODE_T(rw_lock_debug_t) debug_list; /* In the debug version: pointer to the debug info list of the lock */#endif /* UNIV_SYNC_DEBUG */ ulint level; /* Level in the global latching order; default SYNC_LEVEL_NONE */ const char* cfile_name;/* File name where lock created */ ulint cline; /* Line where created */ const char* last_s_file_name;/* File name where last s-locked */ const char* last_x_file_name;/* File name where last x-locked */ ulint last_s_line; /* Line number where last time s-locked */ ulint last_x_line; /* Line number where last time x-locked */ ulint magic_n;};#define RW_LOCK_MAGIC_N 22643#ifdef UNIV_SYNC_DEBUG/* The structure for storing debug info of an rw-lock */struct rw_lock_debug_struct { os_thread_id_t thread_id; /* The thread id of the thread which locked the rw-lock */ ulint pass; /* Pass value given in the lock operation */ ulint lock_type; /* Type of the lock: RW_LOCK_EX, RW_LOCK_SHARED, RW_LOCK_WAIT_EX */ const char* file_name;/* File name where the lock was obtained */ ulint line; /* Line where the rw-lock was locked */ UT_LIST_NODE_T(rw_lock_debug_t) list; /* Debug structs are linked in a two-way list */};#endif /* UNIV_SYNC_DEBUG */#ifndef UNIV_NONINL#include "sync0rw.ic"#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -