1From 2e359284497c361e3208501fc70d49b2c54dc4ef Mon Sep 17 00:00:00 2001 2From: Michael Jeanson <mjeanson@efficios.com> 3Date: Tue, 14 Sep 2021 10:41:08 -0400 4Subject: [PATCH] Always use '__thread' for Thread local storage except on MSVC 5 6Use the GCC extension '__thread' [1] for Thread local storage on all C 7and C++ compilers except MSVC. 8 9While C11 and C++11 respectively offer '_Thread_local' and 10'thread_local' as potentialy faster implementations, they offer no 11guarantees of compatibility when used in a library interface which might 12be used by both C and C++ client code. 13 14[1] https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html 15 16Change-Id: If4fe8bcdbda24b21dedf382112bd5c5f836c00c8 17Signed-off-by: Michael Jeanson <mjeanson@efficios.com> 18Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 19 20[Retrieved from: 21https://github.com/urcu/userspace-rcu/commit/2e359284497c361e3208501fc70d49b2c54dc4ef] 22Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 23--- 24 include/urcu/tls-compat.h | 15 +++++++-------- 25 1 file changed, 7 insertions(+), 8 deletions(-) 26 27diff --git a/include/urcu/tls-compat.h b/include/urcu/tls-compat.h 28index 25cf375a..a2c94ded 100644 29--- a/include/urcu/tls-compat.h 30+++ b/include/urcu/tls-compat.h 31@@ -35,15 +35,14 @@ extern "C" { 32 #ifdef CONFIG_RCU_TLS 33 34 /* 35- * Don't use C++ 'thread_local' on MacOs, the implementation is incompatible 36- * with C and will result in a link error when accessing an extern variable 37- * provided by the C library from C++ code. 38+ * Default to '__thread' on all C and C++ compilers except MSVC. While C11 has 39+ * '_Thread_local' and C++11 has 'thread_local', only '__thread' seems to have 40+ * a compatible implementation when linking public extern symbols across 41+ * language boundaries. 42+ * 43+ * For more details, see 'https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html'. 44 */ 45-#if defined (__cplusplus) && (__cplusplus >= 201103L) && !defined(__APPLE__) 46-# define URCU_TLS_STORAGE_CLASS thread_local 47-#elif defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) 48-# define URCU_TLS_STORAGE_CLASS _Thread_local 49-#elif defined (_MSC_VER) 50+#if defined(_MSC_VER) 51 # define URCU_TLS_STORAGE_CLASS __declspec(thread) 52 #else 53 # define URCU_TLS_STORAGE_CLASS __thread 54