diff --git a/configure.in b/configure.in index d7f250959d1..be6a4a33c65 100644 --- a/configure.in +++ b/configure.in @@ -2342,6 +2342,17 @@ fi fi #---END: +#Check for x86 PAUSE instruction +AC_MSG_CHECKING("for x86 PAUSE instruction") +AC_TRY_COMPILE( +[], +[{__asm__ __volatile__ ("pause");}], +x86_pause_exists=yes, x86_pause_exists=no) +if test "$x86_pause_exists" = "yes" +then + AC_DEFINE([HAVE_PAUSE_INSTRUCTION], [1], [Does x86 PAUSE instruction exist]) +fi + # Check if pthread_attr_setscope() exists AC_CACHE_CHECK("for pthread_attr_setscope", mysql_cv_pthread_attr_setscope, AC_TRY_LINK( diff --git a/storage/innobase/include/ut0ut.h b/storage/innobase/include/ut0ut.h index e64c0f8b4fc..72c8169947b 100644 --- a/storage/innobase/include/ut0ut.h +++ b/storage/innobase/include/ut0ut.h @@ -17,6 +17,19 @@ Created 1/20/1994 Heikki Tuuri typedef time_t ib_time_t; +#ifdef HAVE_PAUSE_INSTRUCTION +#define PAUSE_INSTRUCTION(volatile_var) {__asm__ __volatile__ ("pause");} +#elif +#ifdef UNIV_SYNC_ATOMIC +#define PAUSE_INSTRUCTION(volatile_var) \ + { \ + os_compare_and_swap(volatile_var, 0, 1); \ + } +#elif +#define PAUSE_INSTRUCTION(volatile_var) +#endif +#endif + /************************************************************ Gets the high 32 bits in a ulint. That is makes a shift >> 32, but since there seem to be compiler bugs in both gcc and Visual C++, diff --git a/storage/innobase/ut/ut0ut.c b/storage/innobase/ut/ut0ut.c index 8584d6a8c98..9b45fe279a2 100644 --- a/storage/innobase/ut/ut0ut.c +++ b/storage/innobase/ut/ut0ut.c @@ -336,11 +336,13 @@ ut_delay( ulint delay) /* in: delay in microseconds on 100 MHz Pentium */ { ulint i, j; + volatile lint volatile_var; j = 0; for (i = 0; i < delay * 50; i++) { j += i; + PAUSE_INSTRUCTION(&volatile_var); } if (ut_always_false) {