summaryrefslogtreecommitdiff
path: root/libc/inet/rpc
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2006-12-07 23:24:02 +0000
committerEric Andersen <andersen@codepoet.org>2006-12-07 23:24:02 +0000
commit1478c2de052374c6356db5513749a144c13791b1 (patch)
tree3b22a3f8361f94c99508c497e240ecb71acf8641 /libc/inet/rpc
parent99d6c367c4820a072dc4ada51561df17e2093778 (diff)
Major cleanup of internal mutex locking. Be more consistant in how we do
things, and avoid potential deadlocks caused when a thread holding a uClibc internal lock get canceled and terminates without releasing the lock. This change also provides a single place, bits/uClibc_mutex.h, for thread libraries to modify to change all instances of internal locking.
Diffstat (limited to 'libc/inet/rpc')
-rw-r--r--libc/inet/rpc/create_xid.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/libc/inet/rpc/create_xid.c b/libc/inet/rpc/create_xid.c
index 3b90d7a48..18b9c6e35 100644
--- a/libc/inet/rpc/create_xid.c
+++ b/libc/inet/rpc/create_xid.c
@@ -31,12 +31,9 @@ libc_hidden_proto(gettimeofday)
/* The RPC code is not threadsafe, but new code should be threadsafe. */
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t createxid_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&createxid_lock)
-#define UNLOCK __pthread_mutex_unlock(&createxid_lock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+
static int is_initialized;
static struct drand48_data __rpc_lrand48_data;
@@ -46,7 +43,7 @@ u_long _create_xid (void)
{
unsigned long res;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (!is_initialized)
{
@@ -59,7 +56,7 @@ u_long _create_xid (void)
lrand48_r (&__rpc_lrand48_data, &res);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return res;
}