Commit 73af0753 authored by Marko Mäkelä's avatar Marko Mäkelä

Reduce the number of rw_lock_own() calls

Replace pairs of rw_lock_own() calls with
calls to rw_lock_own_flagged().

These calls are only present in debug builds.
parent d0d073b1
......@@ -529,10 +529,10 @@ btr_search_update_block_hash_info(
buf_block_t* block,
const btr_cur_t* cursor)
{
ut_ad(!rw_lock_own(btr_get_search_latch(cursor->index), RW_LOCK_S));
ut_ad(!rw_lock_own(btr_get_search_latch(cursor->index), RW_LOCK_X));
ut_ad(rw_lock_own(&block->lock, RW_LOCK_S)
|| rw_lock_own(&block->lock, RW_LOCK_X));
ut_ad(!rw_lock_own_flagged(btr_get_search_latch(cursor->index),
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(rw_lock_own_flagged(&block->lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
info->last_hash_succ = FALSE;
......@@ -607,8 +607,8 @@ btr_search_update_hash_ref(
ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);
ut_ad(rw_lock_own(btr_get_search_latch(cursor->index), RW_LOCK_X));
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_S)
|| rw_lock_own(&(block->lock), RW_LOCK_X));
ut_ad(rw_lock_own_flagged(&block->lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(page_align(btr_cur_get_rec(cursor)) == block->frame);
ut_ad(page_is_leaf(block->frame));
assert_block_ahi_valid(block);
......@@ -667,8 +667,8 @@ btr_search_info_update_slow(
buf_block_t* block;
ibool build_index;
ut_ad(!rw_lock_own(btr_get_search_latch(cursor->index), RW_LOCK_S));
ut_ad(!rw_lock_own(btr_get_search_latch(cursor->index), RW_LOCK_X));
ut_ad(!rw_lock_own_flagged(btr_get_search_latch(cursor->index),
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
block = btr_cur_get_block(cursor);
......@@ -1138,8 +1138,8 @@ btr_search_drop_page_hash_index(buf_block_t* block)
ut_ad(block->page.buf_fix_count == 0
|| buf_block_get_state(block) == BUF_BLOCK_REMOVE_HASH
|| rw_lock_own(&block->lock, RW_LOCK_S)
|| rw_lock_own(&block->lock, RW_LOCK_X));
|| rw_lock_own_flagged(&block->lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(page_is_leaf(block->frame));
/* We must not dereference index here, because it could be freed
......@@ -1393,8 +1393,8 @@ btr_search_build_page_hash_index(
ut_ad(page_is_leaf(block->frame));
ut_ad(!rw_lock_own(btr_get_search_latch(index), RW_LOCK_X));
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_S)
|| rw_lock_own(&(block->lock), RW_LOCK_X));
ut_ad(rw_lock_own_flagged(&block->lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
btr_search_s_lock(index);
......
......@@ -4448,8 +4448,9 @@ buf_page_get_gen(
case BUF_GET_IF_IN_POOL_OR_WATCH:
case BUF_PEEK_IF_IN_POOL:
case BUF_EVICT_IF_IN_POOL:
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X));
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S));
ut_ad(!rw_lock_own_flagged(
hash_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
return(NULL);
}
......@@ -4785,8 +4786,8 @@ buf_page_get_gen(
ut_ad(block == fix_block);
ut_ad(fix_block->page.buf_fix_count > 0);
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X));
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S));
ut_ad(!rw_lock_own_flagged(hash_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(buf_block_get_state(fix_block) == BUF_BLOCK_FILE_PAGE);
......@@ -4962,8 +4963,8 @@ buf_page_get_gen(
ut_a(ibuf_count_get(fix_block->page.id) == 0);
#endif
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X));
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S));
ut_ad(!rw_lock_own_flagged(hash_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
return(fix_block);
}
......@@ -5639,8 +5640,8 @@ buf_page_init_for_read(
ibuf_mtr_commit(&mtr);
}
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X));
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S));
ut_ad(!rw_lock_own_flagged(hash_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(!bpage || buf_page_in_file(bpage));
return(bpage);
......
......@@ -1630,8 +1630,8 @@ buf_LRU_free_page(
}
/* buf_LRU_block_remove_hashed() releases the hash_lock */
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X)
&& !rw_lock_own(hash_lock, RW_LOCK_S));
ut_ad(!rw_lock_own_flagged(hash_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
/* We have just freed a BUF_BLOCK_FILE_PAGE. If b != NULL
then it was a compressed page with an uncompressed frame and
......@@ -2184,9 +2184,8 @@ buf_LRU_free_one_page(
}
/* buf_LRU_block_remove_hashed() releases hash_lock and block_mutex */
ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X)
&& !rw_lock_own(hash_lock, RW_LOCK_S));
ut_ad(!rw_lock_own_flagged(hash_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(!mutex_own(block_mutex));
}
......
......@@ -258,9 +258,8 @@ rtr_pcur_getnext_from_path(
rtr_info->tree_savepoints[tree_idx] = mtr_set_savepoint(mtr);
#ifdef UNIV_RTR_DEBUG
ut_ad(!(rw_lock_own(&btr_cur->page_cur.block->lock, RW_LOCK_X)
||
rw_lock_own(&btr_cur->page_cur.block->lock, RW_LOCK_S))
ut_ad(!(rw_lock_own_flagged(&btr_cur->page_cur.block->lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S))
|| my_latch_mode == BTR_MODIFY_TREE
|| my_latch_mode == BTR_CONT_MODIFY_TREE
|| !page_is_leaf(buf_block_get_frame(
......
/*****************************************************************************
Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2018, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -137,11 +138,8 @@ hash_assert_can_search(
if (table->type == HASH_TABLE_SYNC_MUTEX) {
ut_ad(mutex_own(hash_get_mutex(table, fold)));
} else if (table->type == HASH_TABLE_SYNC_RW_LOCK) {
# ifdef UNIV_DEBUG
rw_lock_t* lock = hash_get_lock(table, fold);
ut_ad(rw_lock_own(lock, RW_LOCK_X)
|| rw_lock_own(lock, RW_LOCK_S));
# endif
ut_ad(rw_lock_own_flagged(hash_get_lock(table, fold),
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
} else {
ut_ad(table->type == HASH_TABLE_SYNC_NONE);
}
......
......@@ -281,8 +281,7 @@ rw_lock_s_lock_func(
the threads which have s-locked a latch. This would use some CPU
time. */
ut_ad(!rw_lock_own(lock, RW_LOCK_S)); /* see NOTE above */
ut_ad(!rw_lock_own(lock, RW_LOCK_X));
ut_ad(!rw_lock_own_flagged(lock, RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
if (!rw_lock_s_lock_low(lock, pass, file_name, line)) {
......
......@@ -290,8 +290,8 @@ row_log_online_op(
ut_ad(dtuple_validate(tuple));
ut_ad(dtuple_get_n_fields(tuple) == dict_index_get_n_fields(index));
ut_ad(rw_lock_own(dict_index_get_lock(index), RW_LOCK_S)
|| rw_lock_own(dict_index_get_lock(index), RW_LOCK_X));
ut_ad(rw_lock_own_flagged(&index->lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
if (index->is_corrupted()) {
return;
......
......@@ -1102,8 +1102,8 @@ sel_set_rtr_rec_lock(
rw_lock_x_lock(&(match->block.lock));
retry:
cur_block = btr_pcur_get_block(pcur);
ut_ad(rw_lock_own(&(match->block.lock), RW_LOCK_X)
|| rw_lock_own(&(match->block.lock), RW_LOCK_S));
ut_ad(rw_lock_own_flagged(&match->block.lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
ut_ad(page_is_leaf(buf_block_get_frame(cur_block)));
err = lock_sec_rec_read_check_and_lock(
......
......@@ -265,8 +265,8 @@ row_undo_mod_clust(
ut_ad(thr_get_trx(thr) == node->trx);
ut_ad(node->trx->dict_operation_lock_mode);
ut_ad(node->trx->in_rollback);
ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_S)
|| rw_lock_own(dict_operation_lock, RW_LOCK_X));
ut_ad(rw_lock_own_flagged(dict_operation_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
log_free_check();
pcur = &node->pcur;
......
......@@ -2,7 +2,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, Google Inc.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2018, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
......@@ -1097,12 +1097,12 @@ rw_lock_own_flagged(
const rw_lock_debug_t* info = *it;
ut_ad(os_thread_eq(info->thread_id, os_thread_get_curr_id()));
if (info->pass != 0) {
if (info->pass) {
continue;
}
ut_ad(os_thread_eq(info->thread_id, os_thread_get_curr_id()));
switch (info->lock_type) {
case RW_LOCK_S:
......
/*****************************************************************************
Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2018, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -1510,26 +1510,20 @@ cache_select_table(
trx_i_s_cache_t* cache, /*!< in: whole cache */
enum i_s_table table) /*!< in: which table */
{
i_s_table_cache_t* table_cache;
ut_ad(rw_lock_own(cache->rw_lock, RW_LOCK_S)
|| rw_lock_own(cache->rw_lock, RW_LOCK_X));
ut_ad(rw_lock_own_flagged(cache->rw_lock,
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
switch (table) {
case I_S_INNODB_TRX:
table_cache = &cache->innodb_trx;
break;
return &cache->innodb_trx;
case I_S_INNODB_LOCKS:
table_cache = &cache->innodb_locks;
break;
return &cache->innodb_locks;
case I_S_INNODB_LOCK_WAITS:
table_cache = &cache->innodb_lock_waits;
break;
default:
ut_error;
return &cache->innodb_lock_waits;
}
return(table_cache);
ut_error;
return 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