From 1478c2de052374c6356db5513749a144c13791b1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 7 Dec 2006 23:24:02 +0000 Subject: 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. --- libc/inet/rpc/create_xid.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'libc/inet/rpc') 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 -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 +__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; } -- cgit v1.2.3