Commit 3762ef7d authored by osku's avatar osku

Add 'level' parameter to mutex_create(), remove mutex_set_level().

Rename SYNC_LEVEL_NONE to SYNC_LEVEL_VARYING, add comment clarifying what it
is used for.
parent 35049cac
......@@ -572,8 +572,7 @@ buf_pool_init(
/* 1. Initialize general fields
---------------------------- */
mutex_create(&(buf_pool->mutex));
mutex_set_level(&(buf_pool->mutex), SYNC_BUF_POOL);
mutex_create(&buf_pool->mutex, SYNC_BUF_POOL);
mutex_enter(&(buf_pool->mutex));
......
......@@ -716,8 +716,7 @@ dict_init(void)
{
dict_sys = mem_alloc(sizeof(dict_sys_t));
mutex_create(&(dict_sys->mutex));
mutex_set_level(&(dict_sys->mutex), SYNC_DICT);
mutex_create(&dict_sys->mutex, SYNC_DICT);
dict_sys->table_hash = hash_create(buf_pool_get_max_size() /
(DICT_POOL_PER_TABLE_HASH *
......@@ -737,8 +736,7 @@ dict_init(void)
dict_foreign_err_file = os_file_create_tmpfile();
ut_a(dict_foreign_err_file);
mutex_create(&dict_foreign_err_mutex);
mutex_set_level(&dict_foreign_err_mutex, SYNC_ANY_LATCH);
mutex_create(&dict_foreign_err_mutex, SYNC_ANY_LATCH);
}
/**************************************************************************
......
......@@ -82,8 +82,7 @@ dict_mem_table_create(
table->stat_modified_counter = 0;
mutex_create(&(table->autoinc_mutex));
mutex_set_level(&(table->autoinc_mutex), SYNC_DICT_AUTOINC_MUTEX);
mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
table->autoinc_inited = FALSE;
......
......@@ -1295,9 +1295,7 @@ fil_system_create(
system = mem_alloc(sizeof(fil_system_t));
mutex_create(&(system->mutex));
mutex_set_level(&(system->mutex), SYNC_ANY_LATCH);
mutex_create(&system->mutex, SYNC_ANY_LATCH);
system->spaces = hash_create(hash_size);
system->name_hash = hash_create(hash_size);
......
......@@ -144,9 +144,7 @@ hash_create_mutexes(
table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
for (i = 0; i < n_mutexes; i++) {
mutex_create(table->mutexes + i);
mutex_set_level(table->mutexes + i, sync_level);
mutex_create(table->mutexes + i, sync_level);
}
table->n_mutexes = n_mutexes;
......
......@@ -391,17 +391,12 @@ ibuf_init_at_db_start(void)
}
}
#endif
mutex_create(&ibuf_pessimistic_insert_mutex);
mutex_create(&ibuf_pessimistic_insert_mutex,
SYNC_IBUF_PESS_INSERT_MUTEX);
mutex_set_level(&ibuf_pessimistic_insert_mutex,
SYNC_IBUF_PESS_INSERT_MUTEX);
mutex_create(&ibuf_mutex);
mutex_create(&ibuf_mutex, SYNC_IBUF_MUTEX);
mutex_set_level(&ibuf_mutex, SYNC_IBUF_MUTEX);
mutex_create(&ibuf_bitmap_mutex);
mutex_set_level(&ibuf_bitmap_mutex, SYNC_IBUF_BITMAP_MUTEX);
mutex_create(&ibuf_bitmap_mutex, SYNC_IBUF_BITMAP_MUTEX);
fil_ibuf_init_at_db_start();
......
......@@ -448,8 +448,8 @@ struct rw_lock_struct {
/* 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 */
ulint level; /* Level in the global latching order. */
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 */
......
......@@ -39,7 +39,7 @@ 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. */
#define mutex_create(M) mutex_create_func((M), __FILE__, __LINE__, #M)
#define mutex_create(M, level) mutex_create_func((M), (level), __FILE__, __LINE__, #M)
/*===================*/
/**********************************************************************
Creates, or rather, initializes a mutex object in a specified memory
......@@ -51,6 +51,7 @@ void
mutex_create_func(
/*==============*/
mutex_t* mutex, /* in: pointer to memory */
ulint level, /* in: level */
const char* cfile_name, /* in: file name where created */
ulint cline, /* in: file line where created */
const char* cmutex_name); /* in: mutex name */
......@@ -155,14 +156,6 @@ mutex_validate(
/*===========*/
mutex_t* mutex);
/**********************************************************************
Sets the mutex latching level field. */
void
mutex_set_level(
/*============*/
mutex_t* mutex, /* in: mutex */
ulint level); /* in: level */
/**********************************************************************
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. */
......@@ -171,8 +164,8 @@ void
sync_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 */
ulint level); /* in: level in the latching order; if
SYNC_LEVEL_VARYING, nothing is done */
/**********************************************************************
Removes a latch from the thread level array if it is found there. */
......@@ -383,7 +376,12 @@ or row lock! */
#define SYNC_USER_TRX_LOCK 9999
#define SYNC_NO_ORDER_CHECK 3000 /* this can be used to suppress
latching order checking */
#define SYNC_LEVEL_NONE 2000 /* default: level not defined */
#define SYNC_LEVEL_VARYING 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_DICT_OPERATION 1001 /* table create, drop, etc. reserve
this in X-mode, implicit or backround
operations purge, rollback, foreign
......@@ -473,8 +471,7 @@ struct mutex_struct {
os_thread_id_t thread_id; /* Debug version: The thread id of the
thread which locked the mutex. */
#endif /* UNIV_SYNC_DEBUG */
ulint level; /* Level in the global latching
order; default SYNC_LEVEL_NONE */
ulint level; /* Level in the global latching order */
const char* cfile_name;/* File name where mutex created */
ulint cline; /* Line where created */
ulint magic_n;
......
......@@ -741,8 +741,7 @@ log_init(void)
log_sys = mem_alloc(sizeof(log_t));
mutex_create(&(log_sys->mutex));
mutex_set_level(&(log_sys->mutex), SYNC_LOG);
mutex_create(&log_sys->mutex, SYNC_LOG);
mutex_enter(&(log_sys->mutex));
......
......@@ -112,8 +112,7 @@ recv_sys_create(void)
recv_sys = mem_alloc(sizeof(recv_sys_t));
mutex_create(&(recv_sys->mutex));
mutex_set_level(&(recv_sys->mutex), SYNC_RECV);
mutex_create(&recv_sys->mutex, SYNC_RECV);
recv_sys->heap = NULL;
recv_sys->addr_hash = NULL;
......
......@@ -122,8 +122,7 @@ mem_init(
/* Initialize the hash table */
ut_a(FALSE == mem_hash_initialized);
mutex_create(&mem_hash_mutex);
mutex_set_level(&mem_hash_mutex, SYNC_MEM_HASH);
mutex_create(&mem_hash_mutex, SYNC_MEM_HASH);
for (i = 0; i < MEM_HASH_SIZE; i++) {
UT_LIST_INIT(*mem_hash_get_nth_cell(i));
......
......@@ -204,8 +204,7 @@ mem_pool_create(
pool->buf = ut_malloc_low(size, FALSE, TRUE);
pool->size = size;
mutex_create(&(pool->mutex));
mutex_set_level(&(pool->mutex), SYNC_MEM_POOL);
mutex_create(&pool->mutex, SYNC_MEM_POOL);
/* Initialize the free lists */
......
......@@ -849,11 +849,9 @@ srv_init(void)
srv_sys = mem_alloc(sizeof(srv_sys_t));
kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
mutex_create(&kernel_mutex);
mutex_set_level(&kernel_mutex, SYNC_KERNEL);
mutex_create(&kernel_mutex, SYNC_KERNEL);
mutex_create(&srv_innodb_monitor_mutex);
mutex_set_level(&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
......
......@@ -934,8 +934,7 @@ skip_size_check:
ios = 0;
mutex_create(&ios_mutex);
mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
return(DB_SUCCESS);
}
......@@ -1167,8 +1166,8 @@ NetWare. */
return((int) err);
}
mutex_create(&srv_monitor_file_mutex);
mutex_set_level(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
if (srv_innodb_status) {
srv_monitor_file_name = mem_alloc(
strlen(fil_path_to_mysql_datadir) +
......@@ -1189,15 +1188,15 @@ NetWare. */
}
}
mutex_create(&srv_dict_tmpfile_mutex);
mutex_set_level(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
srv_dict_tmpfile = os_file_create_tmpfile();
if (!srv_dict_tmpfile) {
return(DB_ERROR);
}
mutex_create(&srv_misc_tmpfile_mutex);
mutex_set_level(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
srv_misc_tmpfile = os_file_create_tmpfile();
if (!srv_misc_tmpfile) {
return(DB_ERROR);
......
......@@ -213,8 +213,7 @@ sync_array_create(
if (protection == SYNC_ARRAY_OS_MUTEX) {
arr->os_mutex = os_mutex_create(NULL);
} else if (protection == SYNC_ARRAY_MUTEX) {
mutex_create(&(arr->mutex));
mutex_set_level(&(arr->mutex), SYNC_NO_ORDER_CHECK);
mutex_create(&arr->mutex, SYNC_NO_ORDER_CHECK);
} else {
ut_error;
}
......
......@@ -90,18 +90,17 @@ rw_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 */
ulint cline, /* in: file line where created */
const char* cmutex_name) /* in: mutex name */
{
/* If this is the very first time a synchronization
object is created, then the following call initializes
the sync system. */
/* If this is the very first time a synchronization object is
created, then the following call initializes the sync system. */
mutex_create(rw_lock_get_mutex(lock));
mutex_set_level(rw_lock_get_mutex(lock), SYNC_NO_ORDER_CHECK);
mutex_create(rw_lock_get_mutex(lock), SYNC_NO_ORDER_CHECK);
lock->mutex.cfile_name = cfile_name;
lock->mutex.cline = cline;
#ifndef UNIV_HOTBACKUP
lock->mutex.cmutex_name = cmutex_name;
lock->mutex.mutex_type = 1;
......@@ -117,8 +116,9 @@ rw_lock_create_func(
#ifdef UNIV_SYNC_DEBUG
UT_LIST_INIT(lock->debug_list);
lock->level = SYNC_LEVEL_NONE;
lock->level = SYNC_LEVEL_VARYING;
#endif /* UNIV_SYNC_DEBUG */
lock->magic_n = RW_LOCK_MAGIC_N;
lock->cfile_name = cfile_name;
......
......@@ -202,6 +202,7 @@ void
mutex_create_func(
/*==============*/
mutex_t* mutex, /* in: pointer to memory */
ulint level, /* in: level */
const char* cfile_name, /* in: file name where created */
ulint cline, /* in: file line where created */
const char* cmutex_name) /* in: mutex name */
......@@ -218,7 +219,7 @@ mutex_create_func(
mutex->line = 0;
mutex->file_name = "not yet reserved";
#endif /* UNIV_SYNC_DEBUG */
mutex->level = SYNC_LEVEL_NONE;
mutex->level = level;
mutex->cfile_name = cfile_name;
mutex->cline = cline;
#ifndef UNIV_HOTBACKUP
......@@ -598,19 +599,6 @@ mutex_get_debug_info(
}
#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Sets the mutex latching level field. */
void
mutex_set_level(
/*============*/
mutex_t* mutex, /* in: mutex */
ulint level) /* in: level */
{
mutex->level = level;
}
#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks that the current thread owns the mutex. Works only in the debug
......@@ -979,8 +967,8 @@ void
sync_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 */
ulint level) /* in: level in the latching order; if
SYNC_LEVEL_VARYING, nothing is done */
{
sync_level_t* array;
sync_level_t* slot;
......@@ -1002,7 +990,7 @@ sync_thread_add_level(
return;
}
if (level == SYNC_LEVEL_NONE) {
if (level == SYNC_LEVEL_VARYING) {
return;
}
......@@ -1293,21 +1281,17 @@ sync_init(void)
/* Init the mutex list and create the mutex to protect it. */
UT_LIST_INIT(mutex_list);
mutex_create(&mutex_list_mutex);
mutex_set_level(&mutex_list_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&mutex_list_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&sync_thread_mutex);
mutex_set_level(&sync_thread_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&sync_thread_mutex, SYNC_NO_ORDER_CHECK);
/* Init the rw-lock list and create the mutex to protect it. */
UT_LIST_INIT(rw_lock_list);
mutex_create(&rw_lock_list_mutex);
mutex_set_level(&rw_lock_list_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&rw_lock_list_mutex, SYNC_NO_ORDER_CHECK);
#ifdef UNIV_SYNC_DEBUG
mutex_create(&rw_lock_debug_mutex);
mutex_set_level(&rw_lock_debug_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&rw_lock_debug_mutex, SYNC_NO_ORDER_CHECK);
rw_lock_debug_event = os_event_create(NULL);
rw_lock_debug_waiters = FALSE;
......
......@@ -226,6 +226,5 @@ thr_local_init(void)
thr_local_hash = hash_create(OS_THREAD_MAX_N + 100);
mutex_create(&thr_local_mutex);
mutex_set_level(&thr_local_mutex, SYNC_THR_LOCAL);
mutex_create(&thr_local_mutex, SYNC_THR_LOCAL);
}
......@@ -214,8 +214,7 @@ trx_purge_sys_create(void)
rw_lock_create(&(purge_sys->latch));
rw_lock_set_level(&(purge_sys->latch), SYNC_PURGE_LATCH);
mutex_create(&(purge_sys->mutex));
mutex_set_level(&(purge_sys->mutex), SYNC_PURGE_SYS);
mutex_create(&purge_sys->mutex, SYNC_PURGE_SYS);
purge_sys->heap = mem_heap_create(256);
......
......@@ -147,8 +147,7 @@ trx_rseg_mem_create(
rseg->space = space;
rseg->page_no = page_no;
mutex_create(&(rseg->mutex));
mutex_set_level(&(rseg->mutex), SYNC_RSEG);
mutex_create(&rseg->mutex, SYNC_RSEG);
UT_LIST_ADD_LAST(rseg_list, trx_sys->rseg_list, rseg);
......
......@@ -101,8 +101,7 @@ trx_doublewrite_init(
os_do_not_call_flush_at_each_write = TRUE;
#endif /* UNIV_DO_FLUSH */
mutex_create(&(trx_doublewrite->mutex));
mutex_set_level(&(trx_doublewrite->mutex), SYNC_DOUBLEWRITE);
mutex_create(&trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
trx_doublewrite->first_free = 0;
......
......@@ -144,8 +144,7 @@ trx_create(
trx->repl_wait_binlog_name = NULL;
trx->repl_wait_binlog_pos = 0;
mutex_create(&(trx->undo_mutex));
mutex_set_level(&(trx->undo_mutex), SYNC_TRX_UNDO);
mutex_create(&trx->undo_mutex, SYNC_TRX_UNDO);
trx->rseg = NULL;
......
......@@ -10,8 +10,7 @@ ib_wqueue_create(void)
{
ib_wqueue_t* wq = mem_alloc(sizeof(ib_wqueue_t));
mutex_create(&wq->mutex);
mutex_set_level(&wq->mutex, SYNC_WORK_QUEUE);
mutex_create(&wq->mutex, SYNC_WORK_QUEUE);
wq->items = ib_list_create();
wq->event = os_event_create(NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment