From 4530d787d0a9fbdd3e9a51ec32ff814485f588c8 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Mon, 30 Dec 2013 16:33:50 +0100 Subject: compat: use __atomic operations instead of __sync, when present Fixes #434 Fixes #437 --- compat/atomics.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compat/atomics.h b/compat/atomics.h index e27825de8f..368476a964 100644 --- a/compat/atomics.h +++ b/compat/atomics.h @@ -19,5 +19,12 @@ // At this point both gcc and clang had __sync_synchronize support for some // time. We only support a full memory barrier. -#define mp_memory_barrier() __sync_synchronize() -#define mp_atomic_add_and_fetch(a, b) __sync_add_and_fetch(a, b) +#include "config.h" + +#if HAVE_ATOMIC_BUILTINS +# define mp_memory_barrier() __atomic_thread_fence(__ATOMIC_SEQ_CST) +# define mp_atomic_add_and_fetch(a, b) __atomic_add_fetch(a, b,__ATOMIC_SEQ_CST) +#else +# define mp_memory_barrier() __sync_synchronize() +# define mp_atomic_add_and_fetch(a, b) __sync_add_and_fetch(a, b) +#endif -- cgit v1.2.3