summaryrefslogtreecommitdiff
path: root/libc/stdlib/random.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-12-27 23:30:50 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-12-27 23:30:50 +0000
commitd05dafe2fc23137f8decd641d82d23f45e16281c (patch)
tree83fb903ed075f81269ef2b1ee4b0edf0741ff70f /libc/stdlib/random.c
parentcb19f2f71fa01b6d40dae3190cb6dd1d2116f852 (diff)
Fix a long-standing bug with pthreads. A couple of linuxthreads files
were including libc-lock.h which had a bunch of weak pragmas. Also, uClibc supplied a number of no-op weak thread functions even though many weren't needed. This combined result was that sometimes the functional versions of thread functions in pthread would not override the weaks in libc. While fixing this, I also prepended double-underscore to all necessary weak thread funcs in uClibc, and removed all unused weaks. I did a test build, but haven't tested this since these changes are a backport from my working tree. I did test the changes there and no longer need to explicitly add -lpthread in the perl build for perl to pass its thread self tests.
Diffstat (limited to 'libc/stdlib/random.c')
-rw-r--r--libc/stdlib/random.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/libc/stdlib/random.c b/libc/stdlib/random.c
index bc20d1e1b..b0a00e15c 100644
--- a/libc/stdlib/random.c
+++ b/libc/stdlib/random.c
@@ -34,8 +34,8 @@
data. */
static pthread_mutex_t lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#else
-#define pthread_mutex_lock(x)
-#define pthread_mutex_unlock(x)
+#define __pthread_mutex_lock(x)
+#define __pthread_mutex_unlock(x)
#endif
/* An improved random number generation package. In addition to the standard
@@ -184,9 +184,9 @@ static struct random_data unsafe_state =
for default usage relies on values produced by this routine. */
void srandom (unsigned int x)
{
- pthread_mutex_lock(&lock);
+ __pthread_mutex_lock(&lock);
srandom_r (x, &unsafe_state);
- pthread_mutex_unlock(&lock);
+ __pthread_mutex_unlock(&lock);
}
weak_alias (srandom, srand)
@@ -205,10 +205,10 @@ char * initstate (unsigned int seed, char *arg_state, size_t n)
{
int32_t *ostate;
- pthread_mutex_lock(&lock);
+ __pthread_mutex_lock(&lock);
ostate = &unsafe_state.state[-1];
initstate_r (seed, arg_state, n, &unsafe_state);
- pthread_mutex_unlock(&lock);
+ __pthread_mutex_unlock(&lock);
return (char *) ostate;
}
@@ -224,11 +224,11 @@ char * setstate (char *arg_state)
{
int32_t *ostate;
- pthread_mutex_lock(&lock);
+ __pthread_mutex_lock(&lock);
ostate = &unsafe_state.state[-1];
if (setstate_r (arg_state, &unsafe_state) < 0)
ostate = NULL;
- pthread_mutex_unlock(&lock);
+ __pthread_mutex_unlock(&lock);
return (char *) ostate;
}
@@ -247,9 +247,9 @@ long int random ()
{
int32_t retval;
- pthread_mutex_lock(&lock);
+ __pthread_mutex_lock(&lock);
random_r (&unsafe_state, &retval);
- pthread_mutex_unlock(&lock);
+ __pthread_mutex_unlock(&lock);
return retval;
}