Skip to content

Commit

Permalink
configure: check if __atomic_exchange_n is available.
Browse files Browse the repository at this point in the history
Old compilers may not support __atomic_exchange_n or __ATOMIC_SEQ_CST.

No reviewer.
  • Loading branch information
Sangmin Seo committed Nov 11, 2016
1 parent bce6186 commit 77e4eb6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>],
[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,
Expand Down
2 changes: 2 additions & 0 deletions src/include/abtd_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit 77e4eb6

Please sign in to comment.