=== modified file 'include/my_pthread.h' --- include/my_pthread.h 2013-07-18 14:46:57 +0000 +++ include/my_pthread.h 2013-10-05 07:31:28 +0000 @@ -447,7 +447,6 @@ 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); === modified file 'mysys/thr_mutex.c' --- mysys/thr_mutex.c 2013-06-06 12:51:36 +0000 +++ mysys/thr_mutex.c 2013-10-05 08:33:21 +0000 @@ -865,51 +865,21 @@ int my_pthread_fastmutex_init(my_pthread 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; + uint spins, maxdelay= MY_PTHREAD_FASTMUTEX_DELAY; - for (i= 0; i < mp->spins; i++) + for (spins= mp->spins; spins; spins--) { - res= pthread_mutex_trylock(&mp->mutex); - - if (res == 0) - return 0; - + int res= pthread_mutex_trylock(&mp->mutex); if (res != EBUSY) return res; - mutex_delay(maxdelay); - maxdelay += park_rng(mp) * MY_PTHREAD_FASTMUTEX_DELAY + 1; + maxdelay+= MY_PTHREAD_FASTMUTEX_DELAY; } return pthread_mutex_lock(&mp->mutex); }