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.

91 lines
2.4 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. extern thread_local int x;
  16. thread_local int * ptr = 0;
  17. int foo () { ptr = &x; return x; }
  18. thread_local int x = 1;
  19. ]],
  20. [[x = 2;
  21. foo ();]])],
  22. [ac_cv_thread_local=yes
  23. ax_tls_support=yes],
  24. [ac_cv_thread_local=no],
  25. [ac_cv_thread_local=no])
  26. ])
  27. AS_IF([test "x$ac_cv_thread_local" = "xyes"],
  28. [AC_DEFINE(HAVE_TLS_SUPPORT, [1])
  29. AC_DEFINE(TLS_SUPPORT_CONSTRUCT, [thread_local])])
  30. AS_IF([test "x$ax_tls_support" = "xno"], [
  31. AC_CACHE_CHECK([for __thread], [ac_cv__thread_keyword], [
  32. AC_LINK_IFELSE(
  33. [AC_LANG_PROGRAM(
  34. [[#if defined (__NetBSD__)
  35. #include <sys/param.h>
  36. #if ! __NetBSD_Prereq__(5,1,0)
  37. #error NetBSD __thread support does not work before 5.1.0. It is missing __tls_get_addr.
  38. #endif
  39. #endif
  40. extern __thread int x;
  41. __thread int * ptr = 0;
  42. int foo () { ptr = &x; return x; }
  43. __thread int x = 1;
  44. ]],
  45. [[x = 2;
  46. foo ();
  47. ]])],
  48. [ac_cv__thread_keyword=yes
  49. ax_tls_support=yes],
  50. [ac_cv__thread_keyword=no],
  51. [ac_cv__thread_keyword=no])
  52. ])
  53. AS_IF([test "x$ac_cv__thread_keyword" = "xyes"],
  54. [AC_DEFINE(HAVE_TLS_SUPPORT, [1])
  55. AC_DEFINE(TLS_SUPPORT_CONSTRUCT, [__thread])])])
  56. AS_IF([test "x$ax_tls_support" = "xno"], [
  57. AC_CACHE_CHECK([for __declspec(thread)], [ac_cv_declspec_thread], [
  58. AC_LINK_IFELSE(
  59. [AC_LANG_PROGRAM(
  60. [[
  61. #if defined (__GNUC__)
  62. # error Please fail.
  63. And extra please fail.
  64. #else
  65. extern __declspec(thread) int x;
  66. __declspec(thread) int * ptr = 0;
  67. int foo () { ptr = &x; return x; }
  68. __declspec(thread) int x = 1;
  69. #endif
  70. ]],
  71. [[x = 2;
  72. foo ();]])],
  73. [ac_cv_declspec_thread=yes
  74. ax_tls_support=yes],
  75. [ac_cv_declspec_thread=no],
  76. [ac_cv_declspec_thread=no])])
  77. AS_IF([test "x$ac_cv_declspec_thread" = "xyes"],
  78. [AC_DEFINE(HAVE_TLS_SUPPORT, [1])
  79. AC_DEFINE(TLS_SUPPORT_CONSTRUCT, [__declspec(thread)])])])
  80. ])dnl AX_TLS_SUPPORT