2004-09-13 Thorsten Kukuk * nss/Makefile: Link libnss_files.so against ld.so * nss/nss_files/files-XXX.c: If supported mark static variables as thread local if supported. Don't lock them in this case. * nss/nss_files/files-alias.c: Likewise. * nss/nss_files/files-alias.c: Likewise. --- nss/Makefile +++ nss/Makefile 2004/09/13 08:39:44 @@ -73,6 +73,7 @@ include ../Rules +$(objpfx)libnss_files.so: $(if $(filter yes,$(elf)), $(elfobjdir)/ld.so) ifeq (yes,$(build-static-nss)) $(objpfx)getent: $(objpfx)libnss_files.a --- nss/nss_files/files-alias.c +++ nss/nss_files/files-alias.c 2004/09/13 08:39:44 @@ -1,5 +1,5 @@ /* Mail alias file parser in nss_files module. - Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc. + Copyright (C) 1996,97,98,99,2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. @@ -29,6 +29,7 @@ #include "nsswitch.h" +#if !HAVE___THREAD /* Locks the static variables in this file. */ __libc_lock_define_initialized (static, lock) @@ -37,7 +38,11 @@ static FILE *stream; static fpos_t position; static enum { nouse, getent, getby } last_use; - +#else +static __thread FILE *stream; +static __thread fpos_t position; +static __thread enum { nouse, getent, getby } last_use; +#endif static enum nss_status internal_setent (void) @@ -84,7 +89,9 @@ { enum nss_status status; +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif status = internal_setent (); @@ -97,7 +104,9 @@ last_use = getent; +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return status; } @@ -119,11 +128,15 @@ enum nss_status _nss_files_endaliasent (void) { +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif internal_endent (); +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return NSS_STATUS_SUCCESS; } @@ -377,7 +390,9 @@ /* Return next entry in host file. */ enum nss_status status = NSS_STATUS_SUCCESS; +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif /* Be prepared that the set*ent function was not called before. */ if (stream == NULL) @@ -412,7 +427,9 @@ } } +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return status; } @@ -431,7 +448,9 @@ return NSS_STATUS_UNAVAIL; } +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif /* Open the stream or rest it. */ status = internal_setent (); @@ -449,7 +468,9 @@ internal_endent (); +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return status; } --- nss/nss_files/files-hosts.c +++ nss/nss_files/files-hosts.c 2004/09/13 08:39:44 @@ -86,7 +86,7 @@ { \ enum nss_status status; \ \ - __libc_lock_lock (lock); \ + DO_LOCKING \ \ /* Reset file pointer to beginning or open file. */ \ status = internal_setent (keep_stream); \ @@ -252,7 +252,7 @@ internal_endent (); \ } \ \ - __libc_lock_unlock (lock); \ + DO_UNLOCKING \ \ return status; \ } --- nss/nss_files/files-XXX.c +++ nss/nss_files/files-XXX.c 2004/09/13 08:39:44 @@ -1,5 +1,5 @@ /* Common code for file-based databases in nss_files module. - Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc. + Copyright (C) 1996,1997,1998,1999,2001,2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -56,6 +56,7 @@ # define EXTRA_ARGS_VALUE #endif +#if !HAVE___THREAD /* Locks the static variables in this file. */ __libc_lock_define_initialized (static, lock) @@ -65,6 +66,12 @@ static fpos_t position; static enum { nouse, getent, getby } last_use; static int keep_stream; +#else +static __thread FILE *stream; +static __thread fpos_t position; +static __thread enum { nouse, getent, getby } last_use; +static __thread int keep_stream; +#endif /* Open database file if not already opened. */ static enum nss_status @@ -116,7 +123,9 @@ { enum nss_status status; +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif status = internal_setent (stayopen); @@ -129,7 +138,9 @@ last_use = getent; +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return status; } @@ -151,14 +162,18 @@ enum nss_status CONCAT(_nss_files_end,ENTNAME) (void) { +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif internal_endent (); /* Reset STAYOPEN flag. */ keep_stream = 0; +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return NSS_STATUS_SUCCESS; } @@ -226,7 +241,9 @@ /* Return next entry in host file. */ enum nss_status status = NSS_STATUS_SUCCESS; +#if !HAVE___THREAD __libc_lock_lock (lock); +#endif /* Be prepared that the set*ent function was not called before. */ if (stream == NULL) @@ -269,7 +286,9 @@ } } +#if !HAVE___THREAD __libc_lock_unlock (lock); +#endif return status; } @@ -286,6 +305,14 @@ BREAK_IF_MATCH is a block of code which compares `struct STRUCTURE *result' to the lookup key arguments and does `break;' if they match. */ +#if !HAVE___THREAD +#define DO_LOCKING __libc_lock_lock (lock); +#define DO_UNLOCKING __libc_lock_unlock (lock); +#else +#define DO_LOCKING +#define DO_UNLOCKING +#endif + #define DB_LOOKUP(name, keysize, keypattern, break_if_match, proto...) \ enum nss_status \ _nss_files_get##name##_r (proto, \ @@ -294,7 +321,7 @@ { \ enum nss_status status; \ \ - __libc_lock_lock (lock); \ + DO_LOCKING \ \ /* Reset file pointer to beginning or open file. */ \ status = internal_setent (keep_stream); \ @@ -313,7 +340,7 @@ internal_endent (); \ } \ \ - __libc_lock_unlock (lock); \ + DO_UNLOCKING \ \ return status; \ }