mirror of
https://github.com/MariaDB/server.git
synced 2026-04-20 23:35:32 +02:00
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.
This commit is contained in:
parent
e4212898a6
commit
e562b43222
5 changed files with 0 additions and 131 deletions
|
|
@ -224,9 +224,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG(-ggdb3 DEBUG)
|
|||
OPTION(ENABLED_LOCAL_INFILE
|
||||
"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})
|
||||
IF (WITH_INNODB_DISALLOW_WRITES)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_INNODB_DISALLOW_WRITES")
|
||||
|
|
@ -241,10 +238,6 @@ FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
|
|||
SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
|
||||
"${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF")
|
||||
ENDIF()
|
||||
IF(WITH_FAST_MUTEXES)
|
||||
SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
|
||||
"${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DMY_PTHREAD_FASTMUTEX=1")
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
ENDFOREACH()
|
||||
|
||||
|
|
|
|||
|
|
@ -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_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_wait(A,B) pthread_cond_wait((A), (B))
|
||||
#endif /* MY_PTHREAD_FASTMUTEX */
|
||||
#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 */
|
||||
|
||||
#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS)
|
||||
|
|
|
|||
|
|
@ -71,8 +71,6 @@ struct st_mysql_mutex
|
|||
/** The real mutex. */
|
||||
#ifdef SAFE_MUTEX
|
||||
safe_mutex_t m_mutex;
|
||||
#elif defined(MY_PTHREAD_FASTMUTEX)
|
||||
my_pthread_fastmutex_t m_mutex;
|
||||
#else
|
||||
pthread_mutex_t m_mutex;
|
||||
#endif
|
||||
|
|
@ -619,8 +617,6 @@ static inline int inline_mysql_mutex_init(
|
|||
#endif
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
return pthread_mutex_init(&that->m_mutex, attr);
|
||||
#endif
|
||||
|
|
@ -642,8 +638,6 @@ static inline int inline_mysql_mutex_destroy(
|
|||
#endif
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
return pthread_mutex_destroy(&that->m_mutex);
|
||||
#endif
|
||||
|
|
@ -670,8 +664,6 @@ static inline int inline_mysql_mutex_lock(
|
|||
/* Instrumented code */
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
result= pthread_mutex_lock(&that->m_mutex);
|
||||
#endif
|
||||
|
|
@ -687,8 +679,6 @@ static inline int inline_mysql_mutex_lock(
|
|||
/* Non instrumented code */
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
result= pthread_mutex_lock(&that->m_mutex);
|
||||
#endif
|
||||
|
|
@ -717,8 +707,6 @@ static inline int inline_mysql_mutex_trylock(
|
|||
/* Instrumented code */
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
result= pthread_mutex_trylock(&that->m_mutex);
|
||||
#endif
|
||||
|
|
@ -734,8 +722,6 @@ static inline int inline_mysql_mutex_trylock(
|
|||
/* Non instrumented code */
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
result= pthread_mutex_trylock(&that->m_mutex);
|
||||
#endif
|
||||
|
|
@ -759,8 +745,6 @@ static inline int inline_mysql_mutex_unlock(
|
|||
|
||||
#ifdef SAFE_MUTEX
|
||||
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
|
||||
result= pthread_mutex_unlock(&that->m_mutex);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -105,8 +105,6 @@ void my_mutex_init()
|
|||
|
||||
#if defined(SAFE_MUTEX_DEFINED)
|
||||
safe_mutex_global_init();
|
||||
#elif defined(MY_PTHREAD_FASTMUTEX)
|
||||
fastmutex_global_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -838,88 +836,4 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex,
|
|||
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 /* defined(MY_PTHREAD_FASTMUTEX) && defined(SAFE_MUTEX_DEFINED) */
|
||||
|
|
|
|||
|
|
@ -140,8 +140,6 @@ static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)),
|
|||
/* How to access the pthread_mutex in mysql_mutex_t */
|
||||
#ifdef SAFE_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
|
||||
#define mysql_mutex_real_mutex(A) &(A)->m_mutex
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue