summaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorAlessandro Ghedini <alessandro@ghedini.me>2013-12-30 16:33:50 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-12-31 10:53:36 +0100
commit4530d787d0a9fbdd3e9a51ec32ff814485f588c8 (patch)
tree715478b9aef4d31a175c211565c8288c686275e8 /compat
parente19060d89f219fda16d3bd86e2b3db472f884c98 (diff)
downloadmpv-4530d787d0a9fbdd3e9a51ec32ff814485f588c8.tar.bz2
mpv-4530d787d0a9fbdd3e9a51ec32ff814485f588c8.tar.xz
compat: use __atomic operations instead of __sync, when present
Fixes #434 Fixes #437
Diffstat (limited to 'compat')
-rw-r--r--compat/atomics.h11
1 files 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