📄 sync0rw.h
字号:
/******************************************************The read-write lock (for threads, not for database transactions)(c) 1995 Innobase OyCreated 9/11/1995 Heikki Tuuri*******************************************************/#ifndef sync0rw_h#define sync0rw_h#include "univ.i"#include "ut0lst.h"#include "sync0sync.h"#include "os0sync.h"/* The following undef is to prevent a name conflict with a macroin MySQL: */#undef rw_lock_t/* Latch types; these are used also in btr0btr.h: keep the numerical valuessmaller than 30 and the order of the numerical values like below! */#define RW_S_LATCH 1#define RW_X_LATCH 2#define RW_NO_LATCH 3typedef struct rw_lock_struct rw_lock_t;#ifdef UNIV_SYNC_DEBUGtypedef struct rw_lock_debug_struct rw_lock_debug_t;#endif /* UNIV_SYNC_DEBUG */typedef UT_LIST_BASE_NODE_T(rw_lock_t) rw_lock_list_t;extern rw_lock_list_t rw_lock_list;extern mutex_t rw_lock_list_mutex;#ifdef UNIV_SYNC_DEBUG/* The global mutex which protects debug info lists of all rw-locks.To modify the debug info list of an rw-lock, this mutex has to beacquired in addition to the mutex protecting the lock. */extern mutex_t rw_lock_debug_mutex;extern os_event_t rw_lock_debug_event; /* If deadlock detection does not get immediately the mutex it may wait for this event */extern ibool rw_lock_debug_waiters; /* This is set to TRUE, if there may be waiters for the event */#endif /* UNIV_SYNC_DEBUG */extern ulint rw_s_system_call_count;extern ulint rw_s_spin_wait_count;extern ulint rw_s_exit_count;extern ulint rw_s_os_wait_count;extern ulint rw_x_system_call_count;extern ulint rw_x_spin_wait_count;extern ulint rw_x_os_wait_count;extern ulint rw_x_exit_count;/**********************************************************************Creates, or rather, initializes an rw-lock object in a specified memorylocation (which must be appropriately aligned). The rw-lock is initializedto the non-locked state. Explicit freeing of the rw-lock with rw_lock_freeis necessary only if the memory block containing it is freed. */#define rw_lock_create(L) rw_lock_create_func((L), __FILE__, __LINE__, #L) /*=====================*//**********************************************************************Creates, or rather, initializes an rw-lock object in a specified memorylocation (which must be appropriately aligned). The rw-lock is initializedto the non-locked state. Explicit freeing of the rw-lock with rw_lock_freeis necessary only if the memory block containing it is freed. */voidrw_lock_create_func(/*================*/ rw_lock_t* lock, /* in: pointer to memory */ const char* cfile_name, /* in: file name where created */ ulint cline, /* in: file line where created */ const char* cmutex_name); /* in: mutex name *//**********************************************************************Calling this function is obligatory only if the memory buffer containingthe rw-lock is freed. Removes an rw-lock object from the global list. Therw-lock is checked to be in the non-locked state. */voidrw_lock_free(/*=========*/ rw_lock_t* lock); /* in: rw-lock *//**********************************************************************Checks that the rw-lock has been initialized and that there are nosimultaneous shared and exclusive locks. */iboolrw_lock_validate(/*=============*/ rw_lock_t* lock);/******************************************************************NOTE! The following macros should be used in rw s-locking, not thecorresponding function. */#define rw_lock_s_lock(M) rw_lock_s_lock_func(\ (M), 0, __FILE__, __LINE__)/******************************************************************NOTE! The following macros should be used in rw s-locking, not thecorresponding function. */#define rw_lock_s_lock_gen(M, P) rw_lock_s_lock_func(\ (M), (P), __FILE__, __LINE__)/******************************************************************NOTE! The following macros should be used in rw s-locking, not thecorresponding function. */#define rw_lock_s_lock_nowait(M) rw_lock_s_lock_func_nowait(\ (M), __FILE__, __LINE__)/**********************************************************************NOTE! Use the corresponding macro, not directly this function, except ifyou supply the file name and line number. Lock an rw-lock in shared modefor the current thread. If the rw-lock is locked in exclusive mode, orthere is an exclusive lock request waiting, the function spins a presettime (controlled by SYNC_SPIN_ROUNDS), waiting for the lock, beforesuspending the thread. */UNIV_INLINEvoidrw_lock_s_lock_func(/*================*/ rw_lock_t* lock, /* in: pointer to rw-lock */ ulint pass, /* in: pass value; != 0, if the lock will be passed to another thread to unlock */ const char* file_name,/* in: file name where lock requested */ ulint line); /* in: line where requested *//**********************************************************************NOTE! Use the corresponding macro, not directly this function, except ifyou supply the file name and line number. Lock an rw-lock in shared modefor the current thread if the lock can be acquired immediately. */UNIV_INLINEiboolrw_lock_s_lock_func_nowait(/*=======================*/ /* out: TRUE if success */ rw_lock_t* lock, /* in: pointer to rw-lock */ const char* file_name,/* in: file name where lock requested */ ulint line); /* in: line where requested *//**********************************************************************NOTE! Use the corresponding macro, not directly this function! Lock anrw-lock in exclusive mode for the current thread if the lock can beobtained immediately. */UNIV_INLINEiboolrw_lock_x_lock_func_nowait(/*=======================*/ /* out: TRUE if success */ rw_lock_t* lock, /* in: pointer to rw-lock */ const char* file_name,/* in: file name where lock requested */ ulint line); /* in: line where requested *//**********************************************************************Releases a shared mode lock. */UNIV_INLINEvoidrw_lock_s_unlock_func(/*==================*/ rw_lock_t* lock /* in: rw-lock */#ifdef UNIV_SYNC_DEBUG ,ulint pass /* in: pass value; != 0, if the lock may have been passed to another thread to unlock */#endif );/***********************************************************************Releases a shared mode lock. */#ifdef UNIV_SYNC_DEBUG#define rw_lock_s_unlock(L) rw_lock_s_unlock_func(L, 0)#else#define rw_lock_s_unlock(L) rw_lock_s_unlock_func(L)#endif/***********************************************************************Releases a shared mode lock. */#ifdef UNIV_SYNC_DEBUG#define rw_lock_s_unlock_gen(L, P) rw_lock_s_unlock_func(L, P)#else#define rw_lock_s_unlock_gen(L, P) rw_lock_s_unlock_func(L)#endif/******************************************************************NOTE! The following macro should be used in rw x-locking, not thecorresponding function. */#define rw_lock_x_lock(M) rw_lock_x_lock_func(\ (M), 0, __FILE__, __LINE__)/******************************************************************NOTE! The following macro should be used in rw x-locking, not thecorresponding function. */#define rw_lock_x_lock_gen(M, P) rw_lock_x_lock_func(\ (M), (P), __FILE__, __LINE__)/******************************************************************NOTE! The following macros should be used in rw x-locking, not thecorresponding function. */#define rw_lock_x_lock_nowait(M) rw_lock_x_lock_func_nowait(\ (M), __FILE__, __LINE__)/**********************************************************************NOTE! Use the corresponding macro, not directly this function! Lock anrw-lock in exclusive mode for the current thread. If the rw-lock is lockedin shared or exclusive mode, or there is an exclusive lock request waiting,the function spins a preset time (controlled by SYNC_SPIN_ROUNDS), waitingfor the lock, before suspending the thread. If the same thread has an x-lockon 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 hasan s-lock, locking does not succeed! */voidrw_lock_x_lock_func(/*================*/ rw_lock_t* lock, /* in: pointer to rw-lock */ ulint pass, /* in: pass value; != 0, if the lock will be passed to another thread to unlock */ const char* file_name,/* in: file name where lock requested */ ulint line); /* in: line where requested *//**********************************************************************Releases an exclusive mode lock. */UNIV_INLINEvoidrw_lock_x_unlock_func(/*==================*/ rw_lock_t* lock /* in: rw-lock */#ifdef UNIV_SYNC_DEBUG ,ulint pass /* in: pass value; != 0, if the lock may have been passed to another thread to unlock */#endif );/***********************************************************************Releases an exclusive mode lock. */#ifdef UNIV_SYNC_DEBUG#define rw_lock_x_unlock(L) rw_lock_x_unlock_func(L, 0)#else#define rw_lock_x_unlock(L) rw_lock_x_unlock_func(L)#endif/***********************************************************************Releases an exclusive mode lock. */#ifdef UNIV_SYNC_DEBUG#define rw_lock_x_unlock_gen(L, P) rw_lock_x_unlock_func(L, P)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -