You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.0 KiB

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