📄 sync0sync.h
字号:
/******************************************************Mutex, the basic synchronization primitive(c) 1995 Innobase OyCreated 9/5/1995 Heikki Tuuri*******************************************************/#ifndef sync0sync_h#define sync0sync_h#include "univ.i"#include "sync0types.h"#include "ut0lst.h"#include "ut0mem.h"#include "os0thread.h"#include "os0sync.h"#include "sync0arr.h"#ifndef UNIV_HOTBACKUPextern my_bool timed_mutexes;#endif /* UNIV_HOTBACKUP *//**********************************************************************Initializes the synchronization data structures. */voidsync_init(void);/*===========*//**********************************************************************Frees the resources in synchronization data structures. */voidsync_close(void);/*===========*//**********************************************************************Creates, or rather, initializes a mutex object to a specified memorylocation (which must be appropriately aligned). The mutex is initializedin the reset state. Explicit freeing of the mutex with mutex_free isnecessary only if the memory block containing it is freed. */#define mutex_create(M) mutex_create_func((M), __FILE__, __LINE__, #M)/*===================*//**********************************************************************Creates, or rather, initializes a mutex object in a specified memorylocation (which must be appropriately aligned). The mutex is initializedin the reset state. Explicit freeing of the mutex with mutex_free isnecessary only if the memory block containing it is freed. */voidmutex_create_func(/*==============*/ mutex_t* mutex, /* 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 mutex is freed. Removes a mutex object from the mutex list. The mutexis checked to be in the reset state. */#undef mutex_free /* Fix for MacOS X */voidmutex_free(/*=======*/ mutex_t* mutex); /* in: mutex *//******************************************************************NOTE! The following macro should be used in mutex locking, not thecorresponding function. */#define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)/**********************************************************************A noninlined function that reserves a mutex. In ha_innodb.cc we have disabledinlining of InnoDB functions, and no inlined functions should be called fromthere. That is why we need to duplicate the inlined function here. */voidmutex_enter_noninline(/*==================*/ mutex_t* mutex); /* in: mutex *//******************************************************************NOTE! The following macro should be used in mutex locking, not thecorresponding function. *//* NOTE! currently same as mutex_enter! */#define mutex_enter_fast(M) mutex_enter_func((M), __FILE__, __LINE__)#define mutex_enter_fast_func mutex_enter_func;/**********************************************************************NOTE! Use the corresponding macro in the header file, not this functiondirectly. Locks a mutex for the current thread. If the mutex is reservedthe function spins a preset time (controlled by SYNC_SPIN_ROUNDS) waitingfor the mutex before suspending the thread. */UNIV_INLINEvoidmutex_enter_func(/*=============*/ mutex_t* mutex, /* in: pointer to mutex */ const char* file_name, /* in: file name where locked */ ulint line); /* in: line where locked *//************************************************************************Tries to lock the mutex for the current thread. If the lock is not acquiredimmediately, returns with return value 1. */ulintmutex_enter_nowait(/*===============*/ /* out: 0 if succeed, 1 if not */ mutex_t* mutex, /* in: pointer to mutex */ const char* file_name, /* in: file name where mutex requested */ ulint line); /* in: line where requested *//**********************************************************************Unlocks a mutex owned by the current thread. */UNIV_INLINEvoidmutex_exit(/*=======*/ mutex_t* mutex); /* in: pointer to mutex *//**********************************************************************Releases a mutex. */voidmutex_exit_noninline(/*=================*/ mutex_t* mutex); /* in: mutex *//**********************************************************************Returns TRUE if no mutex or rw-lock is currently locked.Works only in the debug version. */iboolsync_all_freed(void);/*================*//*#####################################################################FUNCTION PROTOTYPES FOR DEBUGGING *//***********************************************************************Prints wait info of the sync system. */voidsync_print_wait_info(/*=================*/ FILE* file); /* in: file where to print *//***********************************************************************Prints info of the sync system. */voidsync_print(/*=======*/ FILE* file); /* in: file where to print *//**********************************************************************Checks that the mutex has been initialized. */iboolmutex_validate(/*===========*/ mutex_t* mutex);/**********************************************************************Sets the mutex latching level field. */voidmutex_set_level(/*============*/ mutex_t* mutex, /* in: mutex */ ulint level); /* in: level *//**********************************************************************Adds a latch and its level in the thread level array. Allocates the memoryfor the array if called first time for this OS thread. Makes the checksagainst other latch levels stored in the array for this thread. */voidsync_thread_add_level(/*==================*/ void* latch, /* in: pointer to a mutex or an rw-lock */ ulint level); /* in: level in the latching order; if SYNC_LEVEL_NONE, nothing is done */ /**********************************************************************Removes a latch from the thread level array if it is found there. */iboolsync_thread_reset_level(/*====================*/ /* out: TRUE if found from the array; it is no error if the latch is not found, as we presently are not able to determine the level for every latch reservation the program does */ void* latch); /* in: pointer to a mutex or an rw-lock *//**********************************************************************Checks that the level array for the current thread is empty. */iboolsync_thread_levels_empty(void);/*==========================*/ /* out: TRUE if empty *//**********************************************************************Checks that the level array for the current thread is empty. */iboolsync_thread_levels_empty_gen(/*=========================*/ /* out: TRUE if empty except the exceptions specified below */ ibool dict_mutex_allowed); /* in: TRUE if dictionary mutex is allowed to be owned by the thread, also purge_is_running mutex is allowed */#ifdef UNIV_SYNC_DEBUG/**********************************************************************Checks that the current thread owns the mutex. Works onlyin the debug version. */iboolmutex_own(/*======*/ /* out: TRUE if owns */ mutex_t* mutex); /* in: mutex *//**********************************************************************Gets the debug information for a reserved mutex. */voidmutex_get_debug_info(/*=================*/ mutex_t* mutex, /* in: mutex */ const char** file_name, /* out: file where requested */ ulint* line, /* out: line where requested */ os_thread_id_t* thread_id); /* out: id of the thread which owns the mutex *//**********************************************************************Counts currently reserved mutexes. Works only in the debug version. */ulintmutex_n_reserved(void);/*==================*//**********************************************************************Prints debug info of currently reserved mutexes. */voidmutex_list_print_info(void);/*========================*/#endif /* UNIV_SYNC_DEBUG *//**********************************************************************NOT to be used outside this module except in debugging! Gets the valueof the lock word. */UNIV_INLINEulintmutex_get_lock_word(/*================*/ mutex_t* mutex); /* in: mutex */#ifdef UNIV_SYNC_DEBUG/**********************************************************************NOT to be used outside this module except in debugging! Gets the waitersfield in a mutex. */UNIV_INLINEulintmutex_get_waiters(/*==============*/ /* out: value to set */ mutex_t* mutex); /* in: mutex */#endif /* UNIV_SYNC_DEBUG *//* LATCHING ORDER WITHIN THE DATABASE ==================================The mutex or latch in the central memory object, for instance, a rollbacksegment object, must be acquired before acquiring the latch or latches tothe corresponding file data structure. In the latching order below, thesefile page object latches are placed immediately below the correspondingcentral memory object latch or mutex.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -