summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/random.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 16:47:01 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 16:47:01 +0000
commit62a21af8006ab04282fdc354c5b4dc765f56d058 (patch)
tree568761d58289238aa14cced3f0010809d4d28c00 /libc/stdlib/random.c
parentef250238dc1572caf859c2b64652f9cdfb0d9e42 (diff)
downloaduClibc-alpine-62a21af8006ab04282fdc354c5b4dc765f56d058.tar.bz2
uClibc-alpine-62a21af8006ab04282fdc354c5b4dc765f56d058.tar.xz
BIG BIG commit: all left files merged from trunk [rev 22714]. Currenntly NPTL sh4 port build and work fine. All committed to allow Khem Ray working on a working branch to integrate the ARM nptl port. MIPS nptl port not tested but should still building and working fine. There are some other part non yet merged with trunk (misc/internals and some headers file that need some more work). Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/stdlib/random.c')
-rw-r--r--libc/stdlib/random.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/libc/stdlib/random.c b/libc/stdlib/random.c
index 80df7890b..3eb8aed8a 100644
--- a/libc/stdlib/random.c
+++ b/libc/stdlib/random.c
@@ -32,14 +32,12 @@ libc_hidden_proto(srandom_r)
libc_hidden_proto(setstate_r)
libc_hidden_proto(initstate_r)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-# include <pthreadP.h>
/* POSIX.1c requires that there is mutual exclusion for the `rand' and
`srand' functions to prevent concurrent calls from modifying common
data. */
-static pthread_mutex_t lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+
/* An improved random number generation package. In addition to the standard
rand()/srand() like interface, this package also has a special state info
@@ -187,9 +185,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);
+ __UCLIBC_MUTEX_LOCK(mylock);
srandom_r (x, &unsafe_state);
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
strong_alias(srandom,srand)
@@ -208,10 +206,10 @@ char * initstate (unsigned int seed, char *arg_state, size_t n)
{
int32_t *ostate;
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
ostate = &unsafe_state.state[-1];
initstate_r (seed, arg_state, n, &unsafe_state);
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return (char *) ostate;
}
@@ -227,11 +225,11 @@ char * setstate (char *arg_state)
{
int32_t *ostate;
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
ostate = &unsafe_state.state[-1];
if (setstate_r (arg_state, &unsafe_state) < 0)
ostate = NULL;
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return (char *) ostate;
}
@@ -251,9 +249,9 @@ long int random (void)
{
int32_t retval;
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
random_r (&unsafe_state, &retval);
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return retval;
}
libc_hidden_def(random)