Commit eb6e2444 authored by irana's avatar irana

branches/innodb+ rb://257

When a transaction joins we check if there are any other transactions
waiting on its locks. If there aren't any waiting then no deadlock can
occur.  This patch however has additional changes.

 1. Count leading zeros
 2. Count trailing zeros

There are two version of both these utility functions. One is hand
coded and the other will use the GCC builtin when available. The
changes to configure have yet to be made.

Simplify the next record lock fetch in the deadlock check code.

Pass the heap number as a parameter to the deadlock check code.

Written by: Sunny
parent 3ac32567
......@@ -217,6 +217,22 @@ store the given number of bits.
@return number of bytes (octets) needed to represent b */
#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
/*************************************************************//**
Calculates the leading zeros in a 32 bint unsigned integer
@return number of leading zeros or ULINT_UNDEFINED if n == 0 */
UNIV_INLINE
ulint
ut_nlz(
/*===*/
ib_uint32_t n); /*!< in: number */
/*************************************************************//**
Calculates the trailing zeros in a 32 bint unsigned integer
@return number of trailing zeros or ULINT_UNDEFINED if n == 0 */
UNIV_INLINE
ulint
ut_ntz(
/*===*/
ib_uint32_t n); /*!< in: number */
/**********************************************************//**
Returns system time. We do not specify the format of the time returned:
the only way to manipulate it is to use the function ut_difftime.
......
......@@ -160,3 +160,68 @@ ut_2_exp(
{
return((ulint) 1 << n);
}
/*************************************************************//**
@return the number of 1s in a 32 bit uint. */
UNIV_INLINE
int
ut_popcount(
/*========*/
ib_uint32_t n)
{
n = n - ((n >> 1) & 0x55555555);
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
n = (n + (n >> 4)) & 0x0F0F0F0F;
n = n + (n << 8);
n = n + (n << 16);
return(n >> 24);
}
/*************************************************************//**
Calculates the leading zeros in a 32 bint unsigned integer
@return number of leading zeros or ULINT_UNDEFINED if n == 0 */
UNIV_INLINE
ulint
ut_nlz(
/*===*/
ib_uint32_t n) /*!< in: number */
{
#ifdef HAVE_GCC_CLZ
return(__builtin_clz(n));
#else
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >>16;
return(ut_popcount(~n));
#endif /* HAVE_GCC_CLZ */
}
/*************************************************************//**
Calculates the trailing zeros in a 32 bint unsigned integer
@return number of trailing zeros or ULINT_UNDEFINED if n == 0 */
UNIV_INLINE
ulint
ut_ntz(
/*===*/
ib_uint32_t n) /*!< in: number */
{
#ifdef HAVE_GCC_CTZ
return(__builtin_ctzl(n));
#else
ib_uint32_t y, bz, b4, b3, b2, b1, b0;
y = n & -n; /* Isolate rightmost 1-bit. */
bz = y ? 0 : 1; /* 1 if y = 0. */
b4 = (y & 0x0000FFFF) ? 0 : 16;
b3 = (y & 0x00FF00FF) ? 0 : 8;
b2 = (y & 0x0F0F0F0F) ? 0 : 4;
b1 = (y & 0x33333333) ? 0 : 2;
b0 = (y & 0x55555555) ? 0 : 1;
return(bz + b4 + b3 + b2 + b1 + b0);
#endif /* HAVE_GCC_CTZ */
}
This diff is collapsed.
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