1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
dnl Check for the __thread/__declspec(thread) construct support.
AC_DEFUN([AX_TLS_SUPPORT],
[
AH_TEMPLATE(HAVE_TLS_SUPPORT,
[Defined if the compiler understands __thread or __declspec(thread)
construct.])
AH_TEMPLATE(TLS_SUPPORT_CONSTRUCT,
[Defined to the actual TLS support construct.])
ax_tls_support=no
AC_CACHE_CHECK([for thread_local], [ac_cv_thread_local],
[
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
// check that pointers to classes work as well
struct S { S () { } void foo () { } int member; };
extern thread_local S * p_s;
thread_local S * p_s = 0;
extern thread_local int x;
thread_local int * ptr = 0;
int foo () { ptr = &x; return x; }
thread_local int x = 1;
]],
[[x = 2;
foo ();
p_s = new S;]])],
[ac_cv_thread_local=yes
ax_tls_support=yes],
[ac_cv_thread_local=no],
[ac_cv_thread_local=no])
])
AS_IF([test "x$ac_cv_thread_local" = "xyes"],
[AC_DEFINE(HAVE_TLS_SUPPORT, [1])
AC_DEFINE(TLS_SUPPORT_CONSTRUCT, [thread_local])])
AS_IF([test "x$ax_tls_support" = "xno"], [
AC_CACHE_CHECK([for __thread], [ac_cv__thread_keyword], [
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#if defined (__NetBSD__)
#include <sys/param.h>
#if ! __NetBSD_Prereq__(5,1,0)
#error NetBSD __thread support does not work before 5.1.0. It is missing __tls_get_addr.
#endif
#endif
// check that pointers to classes work as well
struct S { S () { } void foo () { } int member; };
extern __thread S * p_s;
__thread S * p_s = 0;
extern __thread int x;
__thread int * ptr = 0;
int foo () { ptr = &x; return x; }
__thread int x = 1;
]],
[[x = 2;
foo ();
p_s = new S;
]])],
[ac_cv__thread_keyword=yes
ax_tls_support=yes],
[ac_cv__thread_keyword=no],
[ac_cv__thread_keyword=no])
])
AS_IF([test "x$ac_cv__thread_keyword" = "xyes"],
[AC_DEFINE(HAVE_TLS_SUPPORT, [1])
AC_DEFINE(TLS_SUPPORT_CONSTRUCT, [__thread])])])
AS_IF([test "x$ax_tls_support" = "xno"], [
AC_CACHE_CHECK([for __declspec(thread)], [ac_cv_declspec_thread], [
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#if defined (__GNUC__)
# error Please fail.
And extra please fail.
#else
// check that pointers to classes work as well
struct S { S () { } void foo () { } int member; };
extern __declspec(thread) S * p_s;
__declspec(thread) S * p_s = 0;
extern __declspec(thread) int x;
__declspec(thread) int * ptr = 0;
int foo () { ptr = &x; return x; }
__declspec(thread) int x = 1;
#endif
]],
[[x = 2;
foo ();
p_s = new S;]])],
[ac_cv_declspec_thread=yes
ax_tls_support=yes],
[ac_cv_declspec_thread=no],
[ac_cv_declspec_thread=no])])
AS_IF([test "x$ac_cv_declspec_thread" = "xyes"],
[AC_DEFINE(HAVE_TLS_SUPPORT, [1])
AC_DEFINE(TLS_SUPPORT_CONSTRUCT, [__declspec(thread)])])])
])dnl AX_TLS_SUPPORT
|