Commit 27c54b77 authored by Marko Mäkelä's avatar Marko Mäkelä

Make some locking primitives inline

lock_rec_trx_wait(): Merge to the only caller lock_prdt_rec_move().

lock_rec_reset_nth_bit(), lock_set_lock_and_trx_wait(),
lock_reset_lock_and_trx_wait(): Define in lock0priv.h.
parent d2a15092
...@@ -1064,16 +1064,6 @@ lock_rec_free_all_from_discard_page( ...@@ -1064,16 +1064,6 @@ lock_rec_free_all_from_discard_page(
/*================================*/ /*================================*/
const buf_block_t* block); /*!< in: page to be discarded */ const buf_block_t* block); /*!< in: page to be discarded */
/** Reset the nth bit of a record lock.
@param[in,out] lock record lock
@param[in] i index of the bit that will be reset
@param[in] type whether the lock is in wait mode */
void
lock_rec_trx_wait(
lock_t* lock,
ulint i,
ulint type);
/** The lock system */ /** The lock system */
extern lock_sys_t* lock_sys; extern lock_sys_t* lock_sys;
......
...@@ -35,9 +35,8 @@ those functions in lock/ */ ...@@ -35,9 +35,8 @@ those functions in lock/ */
#endif #endif
#include "univ.i" #include "univ.i"
#include "dict0types.h"
#include "hash0hash.h" #include "hash0hash.h"
#include "trx0types.h" #include "trx0trx.h"
#ifndef UINT32_MAX #ifndef UINT32_MAX
#define UINT32_MAX (4294967295U) #define UINT32_MAX (4294967295U)
...@@ -643,6 +642,28 @@ lock_rec_set_nth_bit( ...@@ -643,6 +642,28 @@ lock_rec_set_nth_bit(
lock_t* lock, /*!< in: record lock */ lock_t* lock, /*!< in: record lock */
ulint i); /*!< in: index of the bit */ ulint i); /*!< in: index of the bit */
/** Reset the nth bit of a record lock.
@param[in,out] lock record lock
@param[in] i index of the bit that will be reset
@return previous value of the bit */
inline byte lock_rec_reset_nth_bit(lock_t* lock, ulint i)
{
ut_ad(lock_get_type_low(lock) == LOCK_REC);
ut_ad(i < lock->un_member.rec_lock.n_bits);
byte* b = reinterpret_cast<byte*>(&lock[1]) + (i >> 3);
byte mask = byte(1U << (i & 7));
byte bit = *b & mask;
*b &= ~mask;
if (bit != 0) {
ut_ad(lock->trx->lock.n_rec_locks > 0);
--lock->trx->lock.n_rec_locks;
}
return(bit);
}
/*********************************************************************//** /*********************************************************************//**
Gets the first or next record lock on a page. Gets the first or next record lock on a page.
@return next lock, NULL if none exists */ @return next lock, NULL if none exists */
...@@ -770,6 +791,33 @@ lock_table_has( ...@@ -770,6 +791,33 @@ lock_table_has(
const dict_table_t* table, /*!< in: table */ const dict_table_t* table, /*!< in: table */
enum lock_mode mode); /*!< in: lock mode */ enum lock_mode mode); /*!< in: lock mode */
/** Set the wait status of a lock.
@param[in,out] lock lock that will be waited for
@param[in,out] trx transaction that will wait for the lock */
inline void lock_set_lock_and_trx_wait(lock_t* lock, trx_t* trx)
{
ut_ad(lock);
ut_ad(lock->trx == trx);
ut_ad(trx->lock.wait_lock == NULL);
ut_ad(lock_mutex_own());
ut_ad(trx_mutex_own(trx));
trx->lock.wait_lock = lock;
lock->type_mode |= LOCK_WAIT;
}
/** Reset the wait status of a lock.
@param[in,out] lock lock that was possibly being waited for */
inline void lock_reset_lock_and_trx_wait(lock_t* lock)
{
ut_ad(lock_get_wait(lock));
ut_ad(lock_mutex_own());
ut_ad(lock->trx->lock.wait_lock == NULL
|| lock->trx->lock.wait_lock == lock);
lock->trx->lock.wait_lock = NULL;
lock->type_mode &= ~LOCK_WAIT;
}
#include "lock0priv.ic" #include "lock0priv.ic"
#endif /* lock0priv_h */ #endif /* lock0priv_h */
...@@ -613,42 +613,6 @@ lock_get_size(void) ...@@ -613,42 +613,6 @@ lock_get_size(void)
return((ulint) sizeof(lock_t)); return((ulint) sizeof(lock_t));
} }
/*********************************************************************//**
Sets the wait flag of a lock and the back pointer in trx to lock. */
UNIV_INLINE
void
lock_set_lock_and_trx_wait(
/*=======================*/
lock_t* lock, /*!< in: lock */
trx_t* trx) /*!< in/out: trx */
{
ut_ad(lock);
ut_ad(lock->trx == trx);
ut_ad(trx->lock.wait_lock == NULL);
ut_ad(lock_mutex_own());
ut_ad(trx_mutex_own(trx));
trx->lock.wait_lock = lock;
lock->type_mode |= LOCK_WAIT;
}
/**********************************************************************//**
The back pointer to a waiting lock request in the transaction is set to NULL
and the wait bit in lock type_mode is reset. */
UNIV_INLINE
void
lock_reset_lock_and_trx_wait(
/*=========================*/
lock_t* lock) /*!< in/out: record lock */
{
ut_ad(lock_get_wait(lock));
ut_ad(lock_mutex_own());
ut_ad(lock->trx->lock.wait_lock == NULL
|| lock->trx->lock.wait_lock == lock);
lock->trx->lock.wait_lock = NULL;
lock->type_mode &= ~LOCK_WAIT;
}
static inline void lock_grant_have_trx_mutex(lock_t* lock) static inline void lock_grant_have_trx_mutex(lock_t* lock)
{ {
lock_reset_lock_and_trx_wait(lock); lock_reset_lock_and_trx_wait(lock);
...@@ -942,49 +906,6 @@ lock_rec_find_set_bit( ...@@ -942,49 +906,6 @@ lock_rec_find_set_bit(
return(ULINT_UNDEFINED); return(ULINT_UNDEFINED);
} }
/** Reset the nth bit of a record lock.
@param[in,out] lock record lock
@param[in] i index of the bit that will be reset
@return previous value of the bit */
UNIV_INLINE
byte
lock_rec_reset_nth_bit(
lock_t* lock,
ulint i)
{
ut_ad(lock_get_type_low(lock) == LOCK_REC);
ut_ad(i < lock->un_member.rec_lock.n_bits);
byte* b = reinterpret_cast<byte*>(&lock[1]) + (i >> 3);
byte mask = static_cast<byte>(1U << (i & 7));
byte bit = *b & mask;
*b &= ~mask;
if (bit != 0) {
ut_ad(lock->trx->lock.n_rec_locks > 0);
--lock->trx->lock.n_rec_locks;
}
return(bit);
}
/** Reset the nth bit of a record lock.
@param[in,out] lock record lock
@param[in] i index of the bit that will be reset
@param[in] type whether the lock is in wait mode */
void
lock_rec_trx_wait(
lock_t* lock,
ulint i,
ulint type)
{
lock_rec_reset_nth_bit(lock, i);
if (type & LOCK_WAIT) {
lock_reset_lock_and_trx_wait(lock);
}
}
/*********************************************************************//** /*********************************************************************//**
Determines if there are explicit record locks on a page. Determines if there are explicit record locks on a page.
@return an explicit record lock on the page, or NULL if there are none */ @return an explicit record lock on the page, or NULL if there are none */
......
...@@ -1028,7 +1028,8 @@ lock_prdt_rec_move( ...@@ -1028,7 +1028,8 @@ lock_prdt_rec_move(
const ulint type_mode = lock->type_mode; const ulint type_mode = lock->type_mode;
lock_prdt_t* lock_prdt = lock_get_prdt_from_lock(lock); lock_prdt_t* lock_prdt = lock_get_prdt_from_lock(lock);
lock_rec_trx_wait(lock, PRDT_HEAPNO, type_mode); lock_rec_reset_nth_bit(lock, PRDT_HEAPNO);
lock_reset_lock_and_trx_wait(lock);
lock_prdt_add_to_queue( lock_prdt_add_to_queue(
type_mode, receiver, lock->index, lock->trx, type_mode, receiver, lock->index, lock->trx,
......
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