svn commit: trunk/uClibc/libc/inet

psm at uclibc.org psm at uclibc.org
Thu Oct 20 21:25:48 UTC 2005


Author: psm
Date: 2005-10-20 14:25:45 -0700 (Thu, 20 Oct 2005)
New Revision: 11900

Log:
Better solution to duplicate locking defines

Modified:
   trunk/uClibc/libc/inet/resolv.c


Changeset:
Modified: trunk/uClibc/libc/inet/resolv.c
===================================================================
--- trunk/uClibc/libc/inet/resolv.c	2005-10-20 19:26:53 UTC (rev 11899)
+++ trunk/uClibc/libc/inet/resolv.c	2005-10-20 21:25:45 UTC (rev 11900)
@@ -647,17 +647,20 @@
 }
 #endif
 
-#ifdef L_dnslookup
+#if defined(L_dnslookup) || defined(L_gethostent)
 
 #ifdef __UCLIBC_HAS_THREADS__
-static pthread_mutex_t dns_mylock = PTHREAD_MUTEX_INITIALIZER;
-# define DNS_LOCK	__pthread_mutex_lock(&dns_mylock)
-# define DNS_UNLOCK	__pthread_mutex_unlock(&dns_mylock);
+static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
+# define LOCK	__pthread_mutex_lock(&mylock)
+# define UNLOCK	__pthread_mutex_unlock(&mylock);
 #else
-# define DNS_LOCK
-# define DNS_UNLOCK
+# define LOCK
+# define UNLOCK
 #endif
+#endif
 
+#ifdef L_dnslookup
+
 /* Just for the record, having to lock __dns_lookup() just for these two globals
  * is pretty lame.  I think these two variables can probably be de-global-ized,
  * which should eliminate the need for doing locking here...  Needs a closer
@@ -693,10 +696,10 @@
 	DPRINTF("Looking up type %d answer for '%s'\n", type, name);
 
 	/* Mess with globals while under lock */
-	DNS_LOCK;
+	LOCK;
 	local_ns = ns % nscount;
 	local_id = id;
-	DNS_UNLOCK;
+	UNLOCK;
 
 	while (retries < MAX_RETRIES) {
 		if (fd != -1)
@@ -900,10 +903,10 @@
 		free(lookup);
 
 		/* Mess with globals while under lock */
-		DNS_LOCK;
+		LOCK;
 		ns = local_ns;
 		id = local_id;
-		DNS_UNLOCK;
+		UNLOCK;
 
 		return (len);				/* success! */
 
@@ -951,10 +954,10 @@
 	h_errno = NETDB_INTERNAL;
 	/* Mess with globals while under lock */
 	if (local_ns != -1) {
-	    DNS_LOCK;
+	    LOCK;
 	    ns = local_ns;
 	    id = local_id;
-	    DNS_UNLOCK;
+	    UNLOCK;
 	}
 	return -1;
 }
@@ -1576,15 +1579,6 @@
 
 #ifdef L_gethostent
 
-#ifdef __UCLIBC_HAS_THREADS__
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
 static int __stay_open;
 static FILE * __gethostent_fp;
 




More information about the uClibc-cvs mailing list