Commit e562b432 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-8111 - remove "fast mutexes"

They aren't faster than normal mutexes. They're disabled by default for years,
so de facto it's dead code, never used.
parent e4212898
...@@ -224,9 +224,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG(-ggdb3 DEBUG) ...@@ -224,9 +224,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG(-ggdb3 DEBUG)
OPTION(ENABLED_LOCAL_INFILE OPTION(ENABLED_LOCAL_INFILE
"If we should should enable LOAD DATA LOCAL by default" ${IF_WIN}) "If we should should enable LOAD DATA LOCAL by default" ${IF_WIN})
OPTION(WITH_FAST_MUTEXES "Compile with fast mutexes" OFF)
MARK_AS_ADVANCED(WITH_FAST_MUTEXES)
OPTION(WITH_INNODB_DISALLOW_WRITES "InnoDB freeze writes patch from Google" ${WITH_WSREP}) OPTION(WITH_INNODB_DISALLOW_WRITES "InnoDB freeze writes patch from Google" ${WITH_WSREP})
IF (WITH_INNODB_DISALLOW_WRITES) IF (WITH_INNODB_DISALLOW_WRITES)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_INNODB_DISALLOW_WRITES") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_INNODB_DISALLOW_WRITES")
...@@ -241,10 +238,6 @@ FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL) ...@@ -241,10 +238,6 @@ FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE} SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
"${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF") "${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF")
ENDIF() ENDIF()
IF(WITH_FAST_MUTEXES)
SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
"${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DMY_PTHREAD_FASTMUTEX=1")
ENDIF()
ENDFOREACH() ENDFOREACH()
ENDFOREACH() ENDFOREACH()
......
...@@ -445,30 +445,10 @@ void safe_mutex_free_deadlock_data(safe_mutex_t *mp); ...@@ -445,30 +445,10 @@ void safe_mutex_free_deadlock_data(safe_mutex_t *mp);
#define safe_mutex_assert_not_owner(mp) do {} while (0) #define safe_mutex_assert_not_owner(mp) do {} while (0)
#define safe_mutex_setflags(mp, F) do {} while (0) #define safe_mutex_setflags(mp, F) do {} while (0)
#if defined(MY_PTHREAD_FASTMUTEX)
#define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A), &(B)->mutex, (C))
#define my_cond_wait(A,B) pthread_cond_wait((A), &(B)->mutex)
#else
#define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A),(B),(C)) #define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A),(B),(C))
#define my_cond_wait(A,B) pthread_cond_wait((A), (B)) #define my_cond_wait(A,B) pthread_cond_wait((A), (B))
#endif /* MY_PTHREAD_FASTMUTEX */
#endif /* !SAFE_MUTEX */ #endif /* !SAFE_MUTEX */
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
typedef struct st_my_pthread_fastmutex_t
{
pthread_mutex_t mutex;
uint spins;
uint rng_state;
} my_pthread_fastmutex_t;
void fastmutex_global_init(void);
int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp,
const pthread_mutexattr_t *attr);
int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp);
#endif /* defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */
/* READ-WRITE thread locking */ /* READ-WRITE thread locking */
#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS) #if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS)
......
...@@ -71,8 +71,6 @@ struct st_mysql_mutex ...@@ -71,8 +71,6 @@ struct st_mysql_mutex
/** The real mutex. */ /** The real mutex. */
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
safe_mutex_t m_mutex; safe_mutex_t m_mutex;
#elif defined(MY_PTHREAD_FASTMUTEX)
my_pthread_fastmutex_t m_mutex;
#else #else
pthread_mutex_t m_mutex; pthread_mutex_t m_mutex;
#endif #endif
...@@ -619,8 +617,6 @@ static inline int inline_mysql_mutex_init( ...@@ -619,8 +617,6 @@ static inline int inline_mysql_mutex_init(
#endif #endif
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
return safe_mutex_init(&that->m_mutex, attr, src_name, src_file, src_line); return safe_mutex_init(&that->m_mutex, attr, src_name, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
return my_pthread_fastmutex_init(&that->m_mutex, attr);
#else #else
return pthread_mutex_init(&that->m_mutex, attr); return pthread_mutex_init(&that->m_mutex, attr);
#endif #endif
...@@ -642,8 +638,6 @@ static inline int inline_mysql_mutex_destroy( ...@@ -642,8 +638,6 @@ static inline int inline_mysql_mutex_destroy(
#endif #endif
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
return safe_mutex_destroy(&that->m_mutex, src_file, src_line); return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
return pthread_mutex_destroy(&that->m_mutex.mutex);
#else #else
return pthread_mutex_destroy(&that->m_mutex); return pthread_mutex_destroy(&that->m_mutex);
#endif #endif
...@@ -670,8 +664,6 @@ static inline int inline_mysql_mutex_lock( ...@@ -670,8 +664,6 @@ static inline int inline_mysql_mutex_lock(
/* Instrumented code */ /* Instrumented code */
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line); result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
result= my_pthread_fastmutex_lock(&that->m_mutex);
#else #else
result= pthread_mutex_lock(&that->m_mutex); result= pthread_mutex_lock(&that->m_mutex);
#endif #endif
...@@ -687,8 +679,6 @@ static inline int inline_mysql_mutex_lock( ...@@ -687,8 +679,6 @@ static inline int inline_mysql_mutex_lock(
/* Non instrumented code */ /* Non instrumented code */
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line); result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
result= my_pthread_fastmutex_lock(&that->m_mutex);
#else #else
result= pthread_mutex_lock(&that->m_mutex); result= pthread_mutex_lock(&that->m_mutex);
#endif #endif
...@@ -717,8 +707,6 @@ static inline int inline_mysql_mutex_trylock( ...@@ -717,8 +707,6 @@ static inline int inline_mysql_mutex_trylock(
/* Instrumented code */ /* Instrumented code */
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line); result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
result= pthread_mutex_trylock(&that->m_mutex.mutex);
#else #else
result= pthread_mutex_trylock(&that->m_mutex); result= pthread_mutex_trylock(&that->m_mutex);
#endif #endif
...@@ -734,8 +722,6 @@ static inline int inline_mysql_mutex_trylock( ...@@ -734,8 +722,6 @@ static inline int inline_mysql_mutex_trylock(
/* Non instrumented code */ /* Non instrumented code */
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line); result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
result= pthread_mutex_trylock(&that->m_mutex.mutex);
#else #else
result= pthread_mutex_trylock(&that->m_mutex); result= pthread_mutex_trylock(&that->m_mutex);
#endif #endif
...@@ -759,8 +745,6 @@ static inline int inline_mysql_mutex_unlock( ...@@ -759,8 +745,6 @@ static inline int inline_mysql_mutex_unlock(
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
result= safe_mutex_unlock(&that->m_mutex, src_file, src_line); result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
#elif defined(MY_PTHREAD_FASTMUTEX)
result= pthread_mutex_unlock(&that->m_mutex.mutex);
#else #else
result= pthread_mutex_unlock(&that->m_mutex); result= pthread_mutex_unlock(&that->m_mutex);
#endif #endif
......
...@@ -105,8 +105,6 @@ void my_mutex_init() ...@@ -105,8 +105,6 @@ void my_mutex_init()
#if defined(SAFE_MUTEX_DEFINED) #if defined(SAFE_MUTEX_DEFINED)
safe_mutex_global_init(); safe_mutex_global_init();
#elif defined(MY_PTHREAD_FASTMUTEX)
fastmutex_global_init();
#endif #endif
} }
...@@ -838,88 +836,4 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex, ...@@ -838,88 +836,4 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex,
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
#elif defined(MY_PTHREAD_FASTMUTEX) /* !SAFE_MUTEX_DEFINED */
static ulong mutex_delay(ulong delayloops)
{
ulong i;
volatile ulong j;
j = 0;
for (i = 0; i < delayloops * 50; i++)
j += i;
return(j);
}
#define MY_PTHREAD_FASTMUTEX_SPINS 8
#define MY_PTHREAD_FASTMUTEX_DELAY 4
static int cpu_count= 0;
int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp,
const pthread_mutexattr_t *attr)
{
if ((cpu_count > 1) && (attr == MY_MUTEX_INIT_FAST))
mp->spins= MY_PTHREAD_FASTMUTEX_SPINS;
else
mp->spins= 0;
mp->rng_state= 1;
return pthread_mutex_init(&mp->mutex, attr);
}
/**
Park-Miller random number generator. A simple linear congruential
generator that operates in multiplicative group of integers modulo n.
x_{k+1} = (x_k g) mod n
Popular pair of parameters: n = 2^32 − 5 = 4294967291 and g = 279470273.
The period of the generator is about 2^31.
Largest value that can be returned: 2147483646 (RAND_MAX)
Reference:
S. K. Park and K. W. Miller
"Random number generators: good ones are hard to find"
Commun. ACM, October 1988, Volume 31, No 10, pages 1192-1201.
*/
static double park_rng(my_pthread_fastmutex_t *mp)
{
mp->rng_state= ((my_ulonglong)mp->rng_state * 279470273U) % 4294967291U;
return (mp->rng_state / 2147483647.0);
}
int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp)
{
int res;
uint i;
uint maxdelay= MY_PTHREAD_FASTMUTEX_DELAY;
for (i= 0; i < mp->spins; i++)
{
res= pthread_mutex_trylock(&mp->mutex);
if (res == 0)
return 0;
if (res != EBUSY)
return res;
mutex_delay(maxdelay);
maxdelay += park_rng(mp) * MY_PTHREAD_FASTMUTEX_DELAY + 1;
}
return pthread_mutex_lock(&mp->mutex);
}
void fastmutex_global_init(void)
{
#ifdef _SC_NPROCESSORS_CONF
cpu_count= sysconf(_SC_NPROCESSORS_CONF);
#endif #endif
}
#endif /* defined(MY_PTHREAD_FASTMUTEX) && defined(SAFE_MUTEX_DEFINED) */
...@@ -140,8 +140,6 @@ static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)), ...@@ -140,8 +140,6 @@ static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)),
/* How to access the pthread_mutex in mysql_mutex_t */ /* How to access the pthread_mutex in mysql_mutex_t */
#ifdef SAFE_MUTEX #ifdef SAFE_MUTEX
#define mysql_mutex_real_mutex(A) &(A)->m_mutex.mutex #define mysql_mutex_real_mutex(A) &(A)->m_mutex.mutex
#elif defined(MY_PTHREAD_FASTMUTEX)
#define mysql_mutex_real_mutex(A) &(A)->m_mutex.mutex
#else #else
#define mysql_mutex_real_mutex(A) &(A)->m_mutex #define mysql_mutex_real_mutex(A) &(A)->m_mutex
#endif #endif
......
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