]> git.sesse.net Git - vlc/blobdiff - src/win32/atomic.c
Converted oss to vlc_clone().
[vlc] / src / win32 / atomic.c
index d6f77c249ef937780a1ed5c43dfb65483c252c4b..14687e665f11116160535b041eaf2399a83cb2e8 100644 (file)
@@ -25,6 +25,8 @@
 #include <vlc_common.h>
 #include <vlc_atomic.h>
 
+#include <windows.h>
+
 uintptr_t vlc_atomic_get (const vlc_atomic_t *atom)
 {
     return atom->u;
@@ -32,15 +34,38 @@ uintptr_t vlc_atomic_get (const vlc_atomic_t *atom)
 
 uintptr_t vlc_atomic_set (vlc_atomic_t *atom, uintptr_t v)
 {
-    atom->u = v;
+#if defined (WIN64)
+    InterlockedExchange64 (&atom->u, v);
+#else
+    InterlockedExchange (&atom->u, v);
+#endif
     return v;
 }
 
 uintptr_t vlc_atomic_add (vlc_atomic_t *atom, uintptr_t v)
 {
 #if defined (WIN64)
-    return InterlockedAdd64 (&atom->s, v);
+    return InterlockedExchangeAdd64 (&atom->s, v) + v;
+#else
+    return InterlockedExchangeAdd (&atom->s, v) + v;
+#endif
+}
+
+uintptr_t vlc_atomic_swap (vlc_atomic_t *atom, uintptr_t v)
+{
+#if defined (WIN64)
+    return InterlockedExchange64 (&atom->s, v);
+#else
+    return InterlockedExchange (&atom->s, v);
+#endif
+}
+
+uintptr_t vlc_atomic_compare_swap (vlc_atomic_t *atom,
+                                   uintptr_t oldval, uintptr_t newval)
+{
+#if defined (WIN64)
+    return InterlockedCompareExchange64 (&atom->s, newval, oldval);
 #else
-    return InterlockedAdd (&atom->s, v);
+    return InterlockedCompareExchange (&atom->s, newval, oldval);
 #endif
 }