InnoDB Plugin  1.0
Data Structures | Macros | Typedefs | Functions | Variables
sync0sync.h File Reference
#include "univ.i"
#include "sync0types.h"
#include "ut0lst.h"
#include "ut0mem.h"
#include "os0thread.h"
#include "os0sync.h"
#include "sync0arr.h"
#include "sync0sync.ic"
Include dependency graph for sync0sync.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ib_mutex_t

Macros

#define mutex_create(K, M, level)   mutex_create_func((M), #M, (level), __FILE__, __LINE__)
#define mutex_enter(M)   mutex_enter_func((M), __FILE__, __LINE__)
#define mutex_enter_nowait(M)   mutex_enter_nowait_func((M), __FILE__, __LINE__)
#define mutex_exit(M)   mutex_exit_func(M)
#define mutex_free(M)   mutex_free_func(M)
#define mutex_enter_fast(M)   mutex_enter_func((M), __FILE__, __LINE__)
#define sync_thread_levels_empty_except_dict()   (!sync_thread_levels_nonempty_gen(TRUE))
#define SYNC_USER_TRX_LOCK   9999
#define SYNC_NO_ORDER_CHECK
#define SYNC_LEVEL_VARYING
#define SYNC_TRX_I_S_RWLOCK
#define SYNC_TRX_I_S_LAST_READ
#define SYNC_FILE_FORMAT_TAG
#define SYNC_DICT_OPERATION
#define SYNC_FTS_CACHE   1005 /* FTS cache rwlock */
#define SYNC_DICT   1000
#define SYNC_DICT_AUTOINC_MUTEX   999
#define SYNC_STATS_AUTO_RECALC   997
#define SYNC_DICT_HEADER   995
#define SYNC_IBUF_HEADER   914
#define SYNC_IBUF_PESS_INSERT_MUTEX   912
#define SYNC_INDEX_TREE   900
#define SYNC_TREE_NODE_NEW   892
#define SYNC_TREE_NODE_FROM_HASH   891
#define SYNC_TREE_NODE   890
#define SYNC_PURGE_LATCH   800
#define SYNC_TRX_UNDO   700
#define SYNC_RSEG   600
#define SYNC_RSEG_HEADER_NEW   591
#define SYNC_RSEG_HEADER   590
#define SYNC_TRX_UNDO_PAGE   570
#define SYNC_EXTERN_STORAGE   500
#define SYNC_FSP   400
#define SYNC_FSP_PAGE   395
#define SYNC_IBUF_MUTEX   370 /* ibuf_mutex */
#define SYNC_IBUF_INDEX_TREE   360
#define SYNC_IBUF_TREE_NODE_NEW   359
#define SYNC_IBUF_TREE_NODE   358
#define SYNC_IBUF_BITMAP_MUTEX   351
#define SYNC_IBUF_BITMAP   350
#define SYNC_INDEX_ONLINE_LOG   340
#define SYNC_LOCK_WAIT_SYS   300
#define SYNC_LOCK_SYS   299
#define SYNC_TRX_SYS   298
#define SYNC_TRX   297
#define SYNC_THREADS   295
#define SYNC_REC_LOCK   294
#define SYNC_TRX_SYS_HEADER   290
#define SYNC_PURGE_QUEUE   200
#define SYNC_LOG   170
#define SYNC_LOG_FLUSH_ORDER   147
#define SYNC_RECV   168
#define SYNC_FTS_TOKENIZE   167
#define SYNC_FTS_CACHE_INIT   166 /* Used for FTS cache initialization */
#define SYNC_FTS_BG_THREADS   165
#define SYNC_FTS_OPTIMIZE   164
#define SYNC_WORK_QUEUE   162
#define SYNC_SEARCH_SYS
#define SYNC_BUF_POOL   150 /* Buffer pool mutex */
#define SYNC_BUF_PAGE_HASH   149 /* buf_pool->page_hash rw_lock */
#define SYNC_BUF_BLOCK   146 /* Block mutex */
#define SYNC_BUF_FLUSH_LIST   145 /* Buffer flush list mutex */
#define SYNC_DOUBLEWRITE   140
#define SYNC_ANY_LATCH   135
#define SYNC_MEM_HASH   131
#define SYNC_MEM_POOL   130
#define RW_LOCK_NOT_LOCKED   350
#define RW_LOCK_EX   351
#define RW_LOCK_EXCLUSIVE   351
#define RW_LOCK_SHARED   352
#define RW_LOCK_WAIT_EX   353
#define SYNC_MUTEX   354
#define MUTEX_MAGIC_N   979585UL
#define SYNC_SPIN_ROUNDS   srv_n_spin_wait_rounds

Typedefs

typedef byte lock_word_t
typedef ut_list_base< ib_mutex_tut_list_base_node_t

Functions

UNIV_INTERN void sync_init (void)
UNIV_INTERN void sync_close (void)
UNIV_INTERN void mutex_create_func (ib_mutex_t *mutex, const char *cmutex_name, ulint level, const char *cfile_name, ulint cline)
UNIV_INTERN void mutex_free_func (ib_mutex_t *mutex)
UNIV_INLINE void mutex_enter_func (ib_mutex_t *mutex, const char *file_name, ulint line)
UNIV_INTERN ulint mutex_enter_nowait_func (ib_mutex_t *mutex, const char *file_name, ulint line)
UNIV_INLINE void mutex_exit_func (ib_mutex_t *mutex)
UNIV_INTERN ibool sync_all_freed (void)
UNIV_INTERN void sync_print_wait_info (FILE *file)
UNIV_INTERN void sync_print (FILE *file)
UNIV_INTERN ibool mutex_validate (const ib_mutex_t *mutex)
UNIV_INTERN ibool mutex_own (const ib_mutex_t *mutex))
UNIV_INTERN void sync_thread_add_level (void *latch, ulint level, ibool relock))
UNIV_INTERN ibool sync_thread_reset_level (void *latch)
UNIV_INTERN void * sync_thread_levels_contains (ulint level)
UNIV_INTERN void * sync_thread_levels_nonempty_gen (ibool dict_mutex_allowed))
UNIV_INTERN void * sync_thread_levels_nonempty_trx (ibool has_search_latch))
UNIV_INTERN void mutex_get_debug_info (ib_mutex_t *mutex, const char **file_name, ulint *line, os_thread_id_t *thread_id)
UNIV_INTERN ulint mutex_n_reserved (void)
UNIV_INLINE lock_word_t mutex_get_lock_word (const ib_mutex_t *mutex)
UNIV_INLINE ulint mutex_get_waiters (const ib_mutex_t *mutex)
UNIV_INLINE void os_atomic_dec_ulint_func (ib_mutex_t *mutex, volatile ulint *var, ulint delta)
UNIV_INLINE void os_atomic_inc_ulint_func (ib_mutex_t *mutex, volatile ulint *var, ulint delta)

Variables

my_bool timed_mutexes
ib_int64_t mutex_exit_count
ibool sync_order_checks_on
ibool sync_initialized
ut_list_base_node_t mutex_list
ib_mutex_t mutex_list_mutex

Detailed Description

Mutex, the basic synchronization primitive

Created 9/5/1995 Heikki Tuuri

Macro Definition Documentation

#define mutex_enter_fast (   M)    mutex_enter_func((M), __FILE__, __LINE__)

NOTE! The following macro should be used in mutex locking, not the corresponding function.

#define MUTEX_MAGIC_N   979585UL

Value of mutex_t::magic_n

#define SYNC_DICT_OPERATION
Value:
1010 /* table create, drop, etc. reserve
this in X-mode; implicit or backround
operations purge, rollback, foreign
key checks reserve this in S-mode */
#define SYNC_FILE_FORMAT_TAG
Value:
1200 /* Used to serialize access to the
file format tag */
#define SYNC_LEVEL_VARYING
Value:
2000 /* Level is varying. Only used with
buffer pool page locks, which do not
have a fixed level, but instead have
their level set after the page is
locked; see e.g.
ibuf_bitmap_get_map_page(). */
#define SYNC_NO_ORDER_CHECK
Value:
3000 /* this can be used to suppress
latching order checking */
#define SYNC_SEARCH_SYS
Value:
160 /* NOTE that if we have a memory
heap that can be extended to the
buffer pool, its logical level is
SYNC_SEARCH_SYS, as memory allocation
can call routines there! Otherwise
the level is SYNC_MEM_HASH. */
#define SYNC_SPIN_ROUNDS   srv_n_spin_wait_rounds
Constant determining how long spin wait is continued before suspending

the thread. A value 600 rounds on a 1995 100 MHz Pentium seems to correspond to 20 microseconds.

#define sync_thread_levels_empty_except_dict ( )    (!sync_thread_levels_nonempty_gen(TRUE))

Checks if the level array for the current thread is empty, except for data dictionary latches.

#define SYNC_TRX_I_S_LAST_READ
Value:
1900 /* Used for
trx_i_s_cache_t::last_read_mutex */
#define SYNC_TRX_I_S_RWLOCK
Value:
1910 /* Used for
trx_i_s_cache_t::rw_lock */

Typedef Documentation

Global list of database mutexes (not OS mutexes) created.

Function Documentation

UNIV_INTERN void mutex_create_func ( ib_mutex_t mutex,
const char *  cmutex_name,
ulint  level,
const char *  cfile_name,
ulint  cline 
)

Creates, or rather, initializes a mutex object in a specified memory location (which must be appropriately aligned). The mutex is initialized in the reset state. Explicit freeing of the mutex with mutex_free is necessary only if the memory block containing it is freed. in: file line where created

Parameters
mutexin: pointer to memory
cmutex_namein: mutex name
levelin: level
cfile_namein: file name where created
UNIV_INLINE void mutex_enter_func ( ib_mutex_t mutex,
const char *  file_name,
ulint  line 
)

NOTE! Use the corresponding macro in the header file, not this function directly. Locks a mutex for the current thread. If the mutex is reserved the function spins a preset time (controlled by SYNC_SPIN_ROUNDS) waiting for the mutex before suspending the thread. in: line where locked

Locks a mutex for the current thread. If the mutex is reserved, the function spins a preset time (controlled by SYNC_SPIN_ROUNDS), waiting for the mutex before suspending the thread.

Parameters
mutexin: pointer to mutex
file_namein: file name where locked
linein: line where locked
UNIV_INTERN ulint mutex_enter_nowait_func ( ib_mutex_t mutex,
const char *  file_name,
ulint  line 
)

NOTE! Use the corresponding macro in the header file, not this function directly. Tries to lock the mutex for the current thread. If the lock is not acquired immediately, returns with return value 1.

Returns
0 if succeed, 1 if not in: line where requested
Parameters
mutexin: pointer to mutex
file_namein: file name where mutex requested
UNIV_INLINE void mutex_exit_func ( ib_mutex_t mutex)

NOTE! Use the corresponding macro mutex_exit(), not directly this function! Unlocks a mutex owned by the current thread. in: pointer to mutex

NOTE! Use the corresponding macro mutex_exit(), not directly this function! Unlocks a mutex owned by the current thread.

Parameters
mutexin: pointer to mutex
UNIV_INTERN void mutex_free_func ( ib_mutex_t mutex)

NOTE! Use the corresponding macro mutex_free(), not directly this function! Calling this function is obligatory only if the memory buffer containing the mutex is freed. Removes a mutex object from the mutex list. The mutex is checked to be in the reset state. in: mutex

UNIV_INTERN void mutex_get_debug_info ( ib_mutex_t mutex,
const char **  file_name,
ulint *  line,
os_thread_id_t thread_id 
)

Gets the debug information for a reserved mutex. out: id of the thread which owns the mutex

Parameters
mutexin: mutex
file_nameout: file where requested
lineout: line where requested
UNIV_INLINE lock_word_t mutex_get_lock_word ( const ib_mutex_t mutex)

NOT to be used outside this module except in debugging! Gets the value of the lock word. in: mutex

Gets the value of the lock word.

Parameters
mutexin: mutex
UNIV_INLINE ulint mutex_get_waiters ( const ib_mutex_t mutex)

NOT to be used outside this module except in debugging! Gets the waiters field in a mutex.

Returns
value to set in: mutex

Gets the waiters field in a mutex.

Returns
value to set

< declared volatile to ensure that the value is read from memory

Parameters
mutexin: mutex
UNIV_INTERN ulint mutex_n_reserved ( void  )

Counts currently reserved mutexes. Works only in the debug version.

Returns
number of reserved mutexes
UNIV_INTERN ibool mutex_own ( const ib_mutex_t mutex)

Checks that the current thread owns the mutex. Works only in the debug version.

Returns
TRUE if owns
Parameters
mutexin: mutex
UNIV_INTERN ibool mutex_validate ( const ib_mutex_t mutex)

Checks that the mutex has been initialized.

Returns
TRUE in: mutex
UNIV_INLINE void os_atomic_dec_ulint_func ( ib_mutex_t mutex,
volatile ulint *  var,
ulint  delta 
)

Function that uses a mutex to decrement a variable atomically in: delta to decrement

Function that uses a mutex to decrement a variable atomically

Parameters
mutexin: mutex guarding the dec
varin/out: variable to decrement
deltain: delta to decrement
UNIV_INLINE void os_atomic_inc_ulint_func ( ib_mutex_t mutex,
volatile ulint *  var,
ulint  delta 
)

Function that uses a mutex to increment a variable atomically in: delta to increment

Function that uses a mutex to increment a variable atomically

Parameters
mutexin: mutex guarding the increment
varin/out: variable to increment
deltain: delta to increment
UNIV_INTERN ibool sync_all_freed ( void  )

Returns TRUE if no mutex or rw-lock is currently locked. Works only in the debug version.

Returns
TRUE if no mutexes and rw-locks reserved
UNIV_INTERN void sync_close ( void  )

Frees the resources in synchronization data structures.

UNIV_INTERN void sync_init ( void  )

Initializes the synchronization data structures.

UNIV_INTERN void sync_print ( FILE *  file)

Prints info of the sync system. in: file where to print

UNIV_INTERN void sync_print_wait_info ( FILE *  file)

Prints wait info of the sync system. in: file where to print

UNIV_INTERN void sync_thread_add_level ( void *  latch,
ulint  level,
ibool  relock 
)

Adds a latch and its level in the thread level array. Allocates the memory for the array if called first time for this OS thread. Makes the checks against other latch levels stored in the array for this thread.

Parameters
latchin: pointer to a mutex or an rw-lock
levelin: level in the latching order; if SYNC_LEVEL_VARYING, nothing is done
relockin: TRUE if re-entering an x-lock
UNIV_INTERN void* sync_thread_levels_contains ( ulint  level)

Checks if the level array for the current thread contains a mutex or rw-latch at the specified level.

Returns
a matching latch, or NULL if not found in: latching order level (SYNC_DICT, ...)
UNIV_INTERN void* sync_thread_levels_nonempty_gen ( ibool  dict_mutex_allowed)

Checks that the level array for the current thread is empty.

Returns
a latch, or NULL if empty except the exceptions specified below
Parameters
dict_mutex_allowedin: TRUE if dictionary mutex is allowed to be owned by the thread
UNIV_INTERN void* sync_thread_levels_nonempty_trx ( ibool  has_search_latch)

Checks if the level array for the current thread is empty, except for the btr_search_latch.

Returns
a latch, or NULL if empty except the exceptions specified below
Parameters
has_search_latchin: TRUE if and only if the thread is supposed to hold btr_search_latch
UNIV_INTERN ibool sync_thread_reset_level ( void *  latch)

Removes a latch from the thread level array if it is found there.

Returns
TRUE if found in 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 in: pointer to a mutex or an rw-lock

Variable Documentation

ib_int64_t mutex_exit_count

The number of mutex_exit calls. Intended for performance monitoring.

ut_list_base_node_t mutex_list

Global list of database mutexes (not OS mutexes) created.

ib_mutex_t mutex_list_mutex

Mutex protecting the mutex_list variable

ibool sync_initialized

This variable is set to TRUE when sync_init is called

ibool sync_order_checks_on

Latching order checks start when this is set TRUE