[vlc-commits] commit: Avoid problems with srand() and speed up a bit (avoid dlsym) ( Rémi Denis-Courmont )
git at videolan.org
git at videolan.org
Sat Apr 17 10:35:57 CEST 2010
vlc/vlc-1.1 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Apr 16 23:29:44 2010 +0300| [4ef62f71cd9cb4cac3c3fc0afbc0237b81ca86e9] | committer: Rémi Denis-Courmont
Avoid problems with srand() and speed up a bit (avoid dlsym)
(cherry picked from commit 1ae21d47f282c15a4f9fed23d3b709ff6a9c2de5)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=4ef62f71cd9cb4cac3c3fc0afbc0237b81ca86e9
---
bin/override.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/bin/override.c b/bin/override.c
index a8b0754..02402d5 100644
--- a/bin/override.c
+++ b/bin/override.c
@@ -148,24 +148,28 @@ int unsetenv (const char *name)
* preserve reproducibility of the number sequence (which usually does not
* matter).
**/
-static pthread_mutex_t prng_lock = PTHREAD_MUTEX_INITIALIZER;
+static struct
+{
+ pthread_mutex_t lock;
+ unsigned int seed;
+} prng = { PTHREAD_MUTEX_INITIALIZER, 0, };
void srand (unsigned int seed)
{
- pthread_mutex_lock (&prng_lock);
+ pthread_mutex_lock (&prng.lock);
LOG("Warning", "%d", seed);
- CALL(srand, seed);
- pthread_mutex_unlock (&prng_lock);
+ prng.seed = seed;
+ pthread_mutex_unlock (&prng.lock);
}
int rand (void)
{
int ret;
- pthread_mutex_lock (&prng_lock);
+ pthread_mutex_lock (&prng.lock);
LOG("Warning", "");
- ret = CALL(rand);
- pthread_mutex_unlock (&prng_lock);
+ ret = rand_r (&prng.seed);
+ pthread_mutex_unlock (&prng.lock);
return ret;
}
More information about the vlc-commits
mailing list