[git commit] Readd the thread local version of __res_state

Austin Foxley austinf at cetoncorp.com
Fri Jul 10 16:27:10 UTC 2009


commit: http://git.uclibc.org/uClibc/commit/?id=9d885748eaf1615cfd9609466b45ccd8cda55cbf
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/nptl


Signed-off-by: Austin Foxley <austinf at cetoncorp.com>
---
 include/resolv.h   |    9 --------
 libc/inet/resolv.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/include/resolv.h b/include/resolv.h
index dd3b300..3b18be6 100644
--- a/include/resolv.h
+++ b/include/resolv.h
@@ -279,14 +279,10 @@ struct res_sym {
 /*			0x00008000	*/
 
 /* Things involving an internal (static) resolver context. */
-#if 0
 __BEGIN_DECLS
 extern struct __res_state *__res_state(void) __attribute__ ((__const__));
 __END_DECLS
 #define _res (*__res_state())
-#else
-extern struct __res_state _res;
-#endif
 
 #define fp_nquery		__fp_nquery
 #define fp_query		__fp_query
@@ -426,10 +422,6 @@ int		res_nsend (res_state, const u_char *, int, u_char *, int)
 void		res_nclose (res_state) __THROW;
 __END_DECLS
 
-/*
- * Current resolv.c is not TLS aware so disable this for now
- */
-#if 0
 # if _LIBC
 #  ifdef __UCLIBC_HAS_THREADS__
 #   if defined __UCLIBC_HAS_TLS__ \
@@ -447,6 +439,5 @@ extern __thread struct __res_state *__resp attribute_tls_model_ie;
 #   endif /* __UCLIBC_HAS_TLS__ */
 #  endif /* __UCLIBC_HAS_THREADS__ */
 # endif /* _LIBC */
-#endif
 
 #endif /* !_RESOLV_H_ */
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 109ae02..7d501f6 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -2843,9 +2843,6 @@ libc_hidden_def(ns_name_unpack)
 
 #ifdef L_res_init
 
-/* Protected by __resolv_lock */
-struct __res_state _res;
-
 /* Will be called under __resolv_lock. */
 static void res_sync_func(void)
 {
@@ -2988,8 +2985,59 @@ void res_close(void)
 	__UCLIBC_MUTEX_UNLOCK(__resolv_lock);
 }
 #endif
+
+/* This needs to be after the use of _res in res_init, above.  */
+#undef _res
+
+#ifndef __UCLIBC_HAS_THREADS__
+/* The resolver state for use by single-threaded programs.
+   This differs from plain `struct __res_state _res;' in that it doesn't
+   create a common definition, but a plain symbol that resides in .bss,
+   which can have an alias.  */
+struct __res_state _res __attribute__((section (".bss")));
+#else //__UCLIBC_HAS_THREADS__
+struct __res_state _res __attribute__((section (".bss"))) attribute_hidden;
+
+# if defined __UCLIBC_HAS_TLS__
+#  undef __resp
+__thread struct __res_state *__resp = &_res;
+/*
+ * FIXME: Add usage of hidden attribute for this when used in the shared
+ *        library. It currently crashes the linker when doing section
+ *        relocations.
+ */
+extern __thread struct __res_state *__libc_resp
+       __attribute__ ((alias ("__resp")));
+# else
+#  undef __resp
+struct __res_state *__resp = &_res;
+# endif
+#endif
+
 #endif /* L_res_init */
 
+#ifdef L_res_state
+# if defined __UCLIBC_HAS_TLS__
+struct __res_state *
+__res_state (void)
+{
+       return __resp;
+}
+# else
+#  undef _res
+extern struct __res_state _res;
+
+/* When threaded, _res may be a per-thread variable.  */
+struct __res_state *
+weak_const_function
+__res_state (void)
+{
+       return &_res;
+}
+# endif
+
+#endif
+
 
 #ifdef L_res_query
 
-- 
1.6.3.3


More information about the uClibc-cvs mailing list