compat: use __atomic operations instead of __sync, when present

Fixes #434
Fixes #437
This commit is contained in:
Alessandro Ghedini 2013-12-30 16:33:50 +01:00 committed by Stefano Pigozzi
parent e19060d89f
commit 4530d787d0
1 changed files with 9 additions and 2 deletions

View File

@ -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