summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Ghedini <alessandro@ghedini.me>2013-12-30 16:33:50 +0100
committerwm4 <wm4@nowhere>2014-01-01 20:57:09 +0100
commit416015f059c52efec14cb4ba7e151d383c743d76 (patch)
tree6c2051d85f9d3f82c08bea40773395d72ac3ae99
parent773db053aabfddb72134a363ecb31c1dac0b8c75 (diff)
downloadmpv-416015f059c52efec14cb4ba7e151d383c743d76.tar.bz2
mpv-416015f059c52efec14cb4ba7e151d383c743d76.tar.xz
compat: use __atomic operations instead of __sync, when present
Fixes #434 Fixes #437
-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