#include <vlc_common.h>
#include <vlc_atomic.h>
+#include <windows.h>
+
uintptr_t vlc_atomic_get (const vlc_atomic_t *atom)
{
return atom->u;
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
}