Skip to content

Commit

Permalink
Cleanup: Remove many C-style lock_get_ accessors
Browse files Browse the repository at this point in the history
Let us prefer member functions to the old C-style accessor functions.
Also, prefer bitwise AND operations for checking multiple flags.
  • Loading branch information
dr-m committed Jan 27, 2021
1 parent cbb0a60 commit 68b2819
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 253 deletions.
9 changes: 0 additions & 9 deletions storage/innobase/include/lock0lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,6 @@ lock_number_of_tables_locked(
const trx_lock_t* trx_lock) /*!< in: transaction locks */
MY_ATTRIBUTE((warn_unused_result));

/*******************************************************************//**
Gets the type of a lock. Non-inline version for using outside of the
lock module.
@return LOCK_TABLE or LOCK_REC */
ulint
lock_get_type(
/*==========*/
const lock_t* lock); /*!< in: lock */

/*******************************************************************//**
Gets the id of the table on which the lock is.
@return id of the table */
Expand Down
18 changes: 0 additions & 18 deletions storage/innobase/include/lock0priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,6 @@ lock_rec_get_first(
const buf_block_t* block, /*!< in: block containing the record */
ulint heap_no);/*!< in: heap number of the record */

/*********************************************************************//**
Gets the mode of a lock.
@return mode */
UNIV_INLINE
enum lock_mode
lock_get_mode(
/*==========*/
const lock_t* lock); /*!< in: lock */

/*********************************************************************//**
Calculates if lock mode 1 is compatible with lock mode 2.
@return nonzero if mode1 compatible with mode2 */
Expand All @@ -570,15 +561,6 @@ lock_mode_stronger_or_eq(
enum lock_mode mode1, /*!< in: lock mode */
enum lock_mode mode2); /*!< in: lock mode */

/*********************************************************************//**
Gets the wait flag of a lock.
@return LOCK_WAIT if waiting, 0 if not */
UNIV_INLINE
ulint
lock_get_wait(
/*==========*/
const lock_t* lock); /*!< in: lock */

/*********************************************************************//**
Checks if a transaction has the specified table lock, or stronger. This
function should only be called by the thread that owns the transaction.
Expand Down
41 changes: 3 additions & 38 deletions storage/innobase/include/lock0priv.ic
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ lock_rec_get_next_on_page(
/*======================*/
lock_t* lock) /*!< in: a record lock */
{
return((lock_t*) lock_rec_get_next_on_page_const(lock));
return const_cast<lock_t*>(lock_rec_get_next_on_page_const(lock));
}

/*********************************************************************//**
Expand All @@ -120,7 +120,6 @@ lock_rec_get_next(
lock_sys.mutex_assert_locked();

do {
ut_ad(!lock->is_table());
lock = lock_rec_get_next_on_page(lock);
} while (lock && !lock_rec_get_nth_bit(lock, heap_no));

Expand Down Expand Up @@ -202,20 +201,6 @@ lock_rec_get_next_on_page_const(
return lock;
}

/*********************************************************************//**
Gets the mode of a lock.
@return mode */
UNIV_INLINE
enum lock_mode
lock_get_mode(
/*==========*/
const lock_t* lock) /*!< in: lock */
{
ut_ad(lock);

return(static_cast<enum lock_mode>(lock->type_mode & LOCK_MODE_MASK));
}

/*********************************************************************//**
Calculates if lock mode 1 is compatible with lock mode 2.
@return nonzero if mode1 compatible with mode2 */
Expand Down Expand Up @@ -248,20 +233,6 @@ lock_mode_stronger_or_eq(
return(lock_strength_matrix[mode1][mode2]);
}

/*********************************************************************//**
Gets the wait flag of a lock.
@return LOCK_WAIT if waiting, 0 if not */
UNIV_INLINE
ulint
lock_get_wait(
/*==========*/
const lock_t* lock) /*!< in: lock */
{
ut_ad(lock);

return(lock->type_mode & LOCK_WAIT);
}

/*********************************************************************//**
Checks if a transaction has the specified table lock, or stronger. This
function should only be called by the thread that owns the transaction.
Expand All @@ -285,22 +256,16 @@ lock_table_has(
continue;
}

lock_mode mode = lock_get_mode(lock);

ut_ad(trx == lock->trx);
ut_ad(lock->is_table());
ut_ad(lock->un_member.tab_lock.table);

if (table == lock->un_member.tab_lock.table
&& lock_mode_stronger_or_eq(mode, in_mode)) {

ut_ad(!lock_get_wait(lock));

&& lock_mode_stronger_or_eq(lock->mode(), in_mode)) {
ut_ad(!lock->is_waiting());
return(lock);
}
}

return(NULL);
}

/* vim: set filetype=c: */
2 changes: 1 addition & 1 deletion storage/innobase/lock/lock0iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ lock_queue_iterator_get_prev(
: UT_LIST_GET_PREV(un_member.tab_lock.locks, iter->current_lock);

if (prev_lock)
iter->current_lock = prev_lock;
iter->current_lock= prev_lock;

return prev_lock;
}
Loading

0 comments on commit 68b2819

Please sign in to comment.