diff options
author | Guilhem Bichot <guilhem@mysql.com> | 2008-11-21 15:21:50 +0100 |
---|---|---|
committer | Guilhem Bichot <guilhem@mysql.com> | 2008-11-21 15:21:50 +0100 |
commit | 33b194c36ec28528fd349dd17412848de2f1171c (patch) | |
tree | 68cba4897925b9395dd0bfe53b5b95a777d78637 /mysys/thr_mutex.c | |
parent | 8d96bcda72df224f7a656cbcc1535a027bada75f (diff) | |
parent | 1d521f6c20881997c9162bd11cadcbc77d20520b (diff) | |
download | mariadb-git-33b194c36ec28528fd349dd17412848de2f1171c.tar.gz |
Merge of 5.1-main into 5.1-maria. There were no changes to storage/myisam, or mysql-test/t/*myisam*.
However there were three new tests mysql-test/suite/parts/t/partition*myisam.test, of which I make here
copies for Maria.
Diffstat (limited to 'mysys/thr_mutex.c')
-rw-r--r-- | mysys/thr_mutex.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index aa46021a938..730fa9f9374 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -458,9 +458,33 @@ int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp, 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; @@ -478,8 +502,7 @@ int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp) return res; mutex_delay(maxdelay); - maxdelay += ((double) random() / (double) RAND_MAX) * - MY_PTHREAD_FASTMUTEX_DELAY + 1; + maxdelay += park_rng(mp) * MY_PTHREAD_FASTMUTEX_DELAY + 1; } return pthread_mutex_lock(&mp->mutex); } |