diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/foundation/win-x86/atomics.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/foundation/win-x86/atomics.h')
-rw-r--r-- | Src/replicant/foundation/win-x86/atomics.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Src/replicant/foundation/win-x86/atomics.h b/Src/replicant/foundation/win-x86/atomics.h new file mode 100644 index 00000000..f61f46d5 --- /dev/null +++ b/Src/replicant/foundation/win-x86/atomics.h @@ -0,0 +1,61 @@ +#pragma once +#include "../../foundation/types.h" +#include <Windows.h> +#include <intrin.h> + +#ifdef __cplusplus +#define NX_ATOMIC_INLINE inline +#else +#define NX_ATOMIC_INLINE +#endif + +NX_ATOMIC_INLINE static size_t nx_atomic_inc(volatile size_t *addr) +{ + return (size_t)_InterlockedIncrement((volatile LONG *)addr); +} + +NX_ATOMIC_INLINE static size_t nx_atomic_dec(volatile size_t *addr) +{ + return (size_t)_InterlockedDecrement((volatile LONG *)addr); +} + +NX_ATOMIC_INLINE static size_t nx_atomic_dec_release(volatile size_t *addr) +{ + return (size_t)_InterlockedDecrement((volatile LONG *)addr); +} + +NX_ATOMIC_INLINE static void nx_atomic_write(size_t value, volatile size_t *addr) +{ + InterlockedExchange((LONG *)addr, value); +} + +NX_ATOMIC_INLINE static void nx_atomic_write_pointer(void *value, void* volatile *addr) +{ + InterlockedExchangePointer(addr, value); +} + +NX_ATOMIC_INLINE static size_t nx_atomic_add(size_t value, volatile size_t* addr) +{ + return (size_t)InterlockedExchangeAdd((volatile LONG *)addr, (LONG)value); +} + +NX_ATOMIC_INLINE static size_t nx_atomic_sub(size_t value, volatile size_t* addr) +{ + return (size_t)InterlockedExchangeAdd((volatile LONG *)addr, -(LONG)value); +} + +NX_ATOMIC_INLINE static void *nx_atomic_swap_pointer(const void *value, void* volatile *addr) +{ + return InterlockedExchangePointer(addr, (PVOID)value); +} + +NX_ATOMIC_INLINE static int nx_atomic_cmpxchg_pointer(void *oldvalue, void *newvalue, void* volatile *addr) +{ + return InterlockedCompareExchangePointer(addr, newvalue, oldvalue) == oldvalue; +} + +#pragma intrinsic(_InterlockedCompareExchange64) +NX_ATOMIC_INLINE static int nx_atomic_cmpxchg2(int64_t oldvalue, int64_t newvalue, volatile int64_t *addr) +{ + return _InterlockedCompareExchange64(addr, newvalue, oldvalue) == oldvalue; +} |