Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/windows/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
# pragma warning( disable : 4996 )
#endif

#ifndef _MSC_VER
#include <stdatomic.h>
/*
* 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
*/
Expand All @@ -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
Expand Down