diff options
author | Peter S. Mazinger <ps.m@gmx.net> | 2005-10-20 21:25:45 +0000 |
---|---|---|
committer | Peter S. Mazinger <ps.m@gmx.net> | 2005-10-20 21:25:45 +0000 |
commit | ec788ca809b14f0ba80abcf268cf8452837b7373 (patch) | |
tree | 74b3cc6986a0f21a41de65036314e46c148310cd | |
parent | 789db36adee475a7b5500beca72fea274360a2bd (diff) |
Better solution to duplicate locking defines
-rw-r--r-- | libc/inet/resolv.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index 389263175..7ac8af805 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -647,17 +647,20 @@ int __form_query(int id, const char *name, int type, unsigned char *packet, } #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 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip, 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 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip, 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 @@ fail: 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 @@ int __read_etc_hosts_r(FILE * fp, const char * name, int type, #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; |