X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=include%2Furcu%2Ftls-compat.h;h=25cf375a23462dc53536c5da2cc4d5206466081b;hb=e915ab84fd0c02d37504f3eb1e1f3be93ea6dc37;hp=c17aca36b2c86a4b94f95e1c97c8aaa327f1f4a7;hpb=cb1f3ebfa99c3d49962fa2421ea3ae33d8dad757;p=urcu.git diff --git a/include/urcu/tls-compat.h b/include/urcu/tls-compat.h index c17aca3..25cf375 100644 --- a/include/urcu/tls-compat.h +++ b/include/urcu/tls-compat.h @@ -32,7 +32,22 @@ extern "C" { #endif -#ifdef CONFIG_RCU_TLS /* Based on ax_tls.m4 */ +#ifdef CONFIG_RCU_TLS + +/* + * Don't use C++ 'thread_local' on MacOs, the implementation is incompatible + * with C and will result in a link error when accessing an extern variable + * provided by the C library from C++ code. + */ +#if defined (__cplusplus) && (__cplusplus >= 201103L) && !defined(__APPLE__) +# define URCU_TLS_STORAGE_CLASS thread_local +#elif defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define URCU_TLS_STORAGE_CLASS _Thread_local +#elif defined (_MSC_VER) +# define URCU_TLS_STORAGE_CLASS __declspec(thread) +#else +# define URCU_TLS_STORAGE_CLASS __thread +#endif /* * Hint: How to define/declare TLS variables of compound types @@ -65,13 +80,13 @@ extern "C" { */ # define DECLARE_URCU_TLS(type, name) \ - CONFIG_RCU_TLS type name + URCU_TLS_STORAGE_CLASS type name # define DEFINE_URCU_TLS(type, name) \ - CONFIG_RCU_TLS type name + URCU_TLS_STORAGE_CLASS type name # define DEFINE_URCU_TLS_INIT(type, name, init) \ - CONFIG_RCU_TLS type name = (init) + URCU_TLS_STORAGE_CLASS type name = (init) # define URCU_TLS(name) (name)