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