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.

83 lines
2.0 KiB

  1. dnl Check for the __sync_add_and_fetch() and __sync_sub_and_fetch()
  2. dnl compiler built-ins.
  3. AC_DEFUN([AX__SYNC],
  4. [
  5. AH_TEMPLATE([HAVE___SYNC_ADD_AND_FETCH],
  6. [Defined if the compiler provides __sync_add_and_fetch().])
  7. AC_CACHE_CHECK([for __sync_add_and_fetch], [ac_cv___sync_add_and_fetch],
  8. [
  9. AC_LINK_IFELSE(
  10. [AC_LANG_PROGRAM(
  11. [[
  12. #include <stdlib.h>
  13. ]],
  14. [[
  15. volatile int x = 1;
  16. volatile int y = __sync_add_and_fetch (&x, 1);
  17. if (x != 2 || y != 2)
  18. abort ();
  19. ]])],
  20. [ac_cv___sync_add_and_fetch=yes],
  21. [ac_cv___sync_add_and_fetch=no])
  22. ])
  23. AS_IF([test "x$ac_cv___sync_add_and_fetch" = "xyes"],
  24. [AC_DEFINE([HAVE___SYNC_ADD_AND_FETCH], [1])])
  25. AH_TEMPLATE([HAVE___SYNC_SUB_AND_FETCH],
  26. [Defined if the compiler provides __sync_sub_and_fetch().])
  27. AC_CACHE_CHECK([for __sync_sub_and_fetch], [ac_cv___sync_sub_and_fetch],
  28. [
  29. AC_LINK_IFELSE(
  30. [AC_LANG_PROGRAM(
  31. [[
  32. #include <stdlib.h>
  33. ]],
  34. [[
  35. volatile int x = 2;
  36. volatile int y = __sync_sub_and_fetch (&x, 1);
  37. if (x != 1 || y != 1)
  38. abort ();
  39. ]])],
  40. [ac_cv___sync_sub_and_fetch=yes],
  41. [ac_cv___sync_sub_and_fetch=no])
  42. ])
  43. AS_IF([test "x$ac_cv___sync_sub_and_fetch" = "xyes"],
  44. [AC_DEFINE([HAVE___SYNC_SUB_AND_FETCH], [1])])
  45. AH_TEMPLATE([HAVE_CXX11_ATOMICS], [Defined if the compiler provides
  46. C++11 <atomic> header and increment, decrement operations.])
  47. AC_CACHE_CHECK([for C++11 atomics], [ac_cv_cxx11_atomics],
  48. [
  49. AC_LINK_IFELSE(
  50. [AC_LANG_PROGRAM(
  51. [[
  52. #include <atomic>
  53. ]],
  54. [[
  55. #define TEST_ATOMIC(type) do { \
  56. std::atomic<type> x (0); \
  57. std::atomic_fetch_add_explicit (&x, static_cast<type>(1), std::memory_order_acquire); \
  58. std::atomic_fetch_sub_explicit (&x, static_cast<type>(1), std::memory_order_release); \
  59. } while (0)
  60. TEST_ATOMIC(int);
  61. TEST_ATOMIC(unsigned int);
  62. TEST_ATOMIC(long);
  63. TEST_ATOMIC(unsigned long);
  64. std::atomic_thread_fence (std::memory_order_acquire);
  65. ]])],
  66. [ac_cv_cxx11_atomics=yes],
  67. [ac_cv_cxx11_atomics=no])
  68. ])
  69. AS_IF([test "x$ac_cv_cxx11_atomics" = "xyes"],
  70. [AC_DEFINE([HAVE_CXX11_ATOMICS], [1])])
  71. ])