diff --git a/configure.ac b/configure.ac index 81aa36ff2..73250ca05 100644 --- a/configure.ac +++ b/configure.ac @@ -554,6 +554,23 @@ AS_IF([test "x$enable_sched_sleep" = "xyes"], [Define to make the scheduler sleep when its pools are empty])]) +# check if __atomic_exchange_n() is supported +AC_TRY_COMPILE( +[#include ], +[uint32_t val = 0; + uint32_t old = __atomic_exchange_n(&val, 2, __ATOMIC_SEQ_CST);], +[have_atomic_exchange=yes], +[have_atomic_exchange=no] +) +if test "x$have_atomic_exchange" = "xyes" ; then + AC_DEFINE(ABT_CONFIG_HAVE_ATOMIC_EXCHANGE, 1, + [Define if __atomic_exchange_n is supported]) +else + # If __atomic_exchange_n is not supported, we have to use the simple mutex + # implementation. + enable_simple_mutex=yes +fi + # --enable-simple-mutex AS_IF([test "x$enable_simple_mutex" = "xyes"], [AC_DEFINE(ABT_CONFIG_USE_SIMPLE_MUTEX, 1, diff --git a/src/include/abtd_atomic.h b/src/include/abtd_atomic.h index 9f68dfc61..704bc759d 100644 --- a/src/include/abtd_atomic.h +++ b/src/include/abtd_atomic.h @@ -175,6 +175,7 @@ uint64_t ABTD_atomic_fetch_xor_uint64(uint64_t *ptr, uint64_t v) return __sync_fetch_and_xor(ptr, v); } +#ifdef ABT_CONFIG_HAVE_ATOMIC_EXCHANGE static inline int32_t ABTD_atomic_exchange_int32(int32_t *ptr, int32_t v) { @@ -198,6 +199,7 @@ uint64_t ABTD_atomic_exchange_uint64(uint64_t *ptr, uint64_t v) { return __atomic_exchange_n(ptr, v, __ATOMIC_SEQ_CST); } +#endif static inline void ABTD_atomic_mem_barrier(void)