From 1bc4e40860e73cce4d1c576479f7a8e5397e0990 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 15 Jun 2022 20:18:59 -0700 Subject: [PATCH] replace windows atomic operations with stdatomic Signed-off-by: Rosen Penev --- src/windows/platform.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/windows/platform.h b/src/windows/platform.h index 1a99903b..0704bb7c 100644 --- a/src/windows/platform.h +++ b/src/windows/platform.h @@ -42,6 +42,20 @@ # pragma warning( disable : 4996 ) #endif +#ifndef _MSC_VER +#include +/* + * C11 atomic operations + */ +#define atomic_inc(p) (atomic_fetch_add((p), 1) + 1) +#define atomic_dec(p) (atomic_fetch_sub((p), 1) - 1) + +/* We use compound literals here to stop the 'expected' values from being overwritten */ +#define atomic_cas(p, oval, nval) atomic_compare_exchange_strong(p, &(__typeof__(oval)){ oval }, nval) +#define atomic_ptr_cas(p, oval, nval) atomic_compare_exchange_strong(p, (&(uintptr_t){ (uintptr_t)oval }), (uintptr_t)nval) +#define atomic_ptr_swap(p, nval) atomic_exchange(p, (uintptr_t)nval) +#define atomic_ptr_load(p) atomic_load(p) +#else /* * Atomic integer operations */ @@ -54,6 +68,7 @@ #define atomic_ptr_swap(p, oval) InterlockedExchangePointer(p, oval) #define atomic_ptr_load(p) (*p) +#endif /* * Additional members of struct kqueue