Commit 81a3b5d0 authored by David Reid's avatar David Reid

Update c89atomic.

parent a389b65a
...@@ -8255,7 +8255,6 @@ typedef unsigned int c89atomic_uint32; ...@@ -8255,7 +8255,6 @@ typedef unsigned int c89atomic_uint32;
#endif #endif
typedef int c89atomic_memory_order; typedef int c89atomic_memory_order;
typedef unsigned char c89atomic_bool; typedef unsigned char c89atomic_bool;
typedef unsigned char c89atomic_flag;
#if !defined(C89ATOMIC_64BIT) && !defined(C89ATOMIC_32BIT) #if !defined(C89ATOMIC_64BIT) && !defined(C89ATOMIC_32BIT)
#ifdef _WIN32 #ifdef _WIN32
#ifdef _WIN64 #ifdef _WIN64
...@@ -8302,6 +8301,10 @@ typedef unsigned char c89atomic_flag; ...@@ -8302,6 +8301,10 @@ typedef unsigned char c89atomic_flag;
#else #else
#define C89ATOMIC_INLINE #define C89ATOMIC_INLINE
#endif #endif
#define C89ATOMIC_HAS_8
#define C89ATOMIC_HAS_16
#define C89ATOMIC_HAS_32
#define C89ATOMIC_HAS_64
#if (defined(_MSC_VER) ) || defined(__WATCOMC__) || defined(__DMC__) #if (defined(_MSC_VER) ) || defined(__WATCOMC__) || defined(__DMC__)
#define c89atomic_memory_order_relaxed 0 #define c89atomic_memory_order_relaxed 0
#define c89atomic_memory_order_consume 1 #define c89atomic_memory_order_consume 1
...@@ -8309,75 +8312,93 @@ typedef unsigned char c89atomic_flag; ...@@ -8309,75 +8312,93 @@ typedef unsigned char c89atomic_flag;
#define c89atomic_memory_order_release 3 #define c89atomic_memory_order_release 3
#define c89atomic_memory_order_acq_rel 4 #define c89atomic_memory_order_acq_rel 4
#define c89atomic_memory_order_seq_cst 5 #define c89atomic_memory_order_seq_cst 5
#if _MSC_VER >= 1400 #if _MSC_VER < 1600 && defined(C89ATOMIC_32BIT)
#include <intrin.h> #define C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint8)_InterlockedExchange8((volatile char*)dst, (char)src);
}
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint16)_InterlockedExchange16((volatile short*)dst, (short)src);
}
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint32)_InterlockedExchange((volatile long*)dst, (long)src);
}
#if defined(C89ATOMIC_64BIT)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint64)_InterlockedExchange64((volatile long long*)dst, (long long)src);
}
#endif #endif
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) #if _MSC_VER < 1600
{ #undef C89ATOMIC_HAS_8
(void)order; #undef C89ATOMIC_HAS_16
return (c89atomic_uint8)_InterlockedExchangeAdd8((volatile char*)dst, (char)src);
}
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint16)_InterlockedExchangeAdd16((volatile short*)dst, (short)src);
}
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint32)_InterlockedExchangeAdd((volatile long*)dst, (long)src);
}
#if defined(C89ATOMIC_64BIT)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint64)_InterlockedExchangeAdd64((volatile long long*)dst, (long long)src);
}
#endif #endif
#define c89atomic_compare_and_swap_8( dst, expected, desired) (c89atomic_uint8 )_InterlockedCompareExchange8 ((volatile char* )dst, (char )desired, (char )expected) #if !defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
#define c89atomic_compare_and_swap_16(dst, expected, desired) (c89atomic_uint16)_InterlockedCompareExchange16((volatile short* )dst, (short )desired, (short )expected) #include <intrin.h>
#define c89atomic_compare_and_swap_32(dst, expected, desired) (c89atomic_uint32)_InterlockedCompareExchange ((volatile long* )dst, (long )desired, (long )expected)
#define c89atomic_compare_and_swap_64(dst, expected, desired) (c89atomic_uint64)_InterlockedCompareExchange64((volatile long long*)dst, (long long)desired, (long long)expected)
#if defined(C89ATOMIC_X64)
#define c89atomic_thread_fence(order) __faststorefence(), (void)order
#else
static C89ATOMIC_INLINE void c89atomic_thread_fence(c89atomic_memory_order order)
{
volatile c89atomic_uint32 barrier = 0;
(void)order;
c89atomic_fetch_add_explicit_32(&barrier, 0, order);
}
#endif #endif
#else #if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
#if defined(C89ATOMIC_X86) #if defined(C89ATOMIC_HAS_8)
static C89ATOMIC_INLINE void __stdcall c89atomic_thread_fence(c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_compare_and_swap_8(volatile c89atomic_uint8* dst, c89atomic_uint8 expected, c89atomic_uint8 desired)
{ {
(void)order; c89atomic_uint8 result = 0;
__asm { __asm {
lock add [esp], 0 mov ecx, dst
mov al, expected
mov dl, desired
lock cmpxchg [ecx], dl
mov result, al
}
return result;
}
#endif
#if defined(C89ATOMIC_HAS_16)
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_compare_and_swap_16(volatile c89atomic_uint16* dst, c89atomic_uint16 expected, c89atomic_uint16 desired)
{
c89atomic_uint16 result = 0;
__asm {
mov ecx, dst
mov ax, expected
mov dx, desired
lock cmpxchg [ecx], dx
mov result, ax
}
return result;
}
#endif
#if defined(C89ATOMIC_HAS_32)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_compare_and_swap_32(volatile c89atomic_uint32* dst, c89atomic_uint32 expected, c89atomic_uint32 desired)
{
c89atomic_uint32 result = 0;
__asm {
mov ecx, dst
mov eax, expected
mov edx, desired
lock cmpxchg [ecx], edx
mov result, eax
} }
return result;
} }
#endif
#if defined(C89ATOMIC_HAS_64)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_compare_and_swap_64(volatile c89atomic_uint64* dst, c89atomic_uint64 expected, c89atomic_uint64 desired)
{
c89atomic_uint32 resultEAX = 0;
c89atomic_uint32 resultEDX = 0;
__asm {
mov esi, dst
mov eax, dword ptr expected
mov edx, dword ptr expected + 4
mov ebx, dword ptr desired
mov ecx, dword ptr desired + 4
lock cmpxchg8b qword ptr [esi]
mov resultEAX, eax
mov resultEDX, edx
}
return ((c89atomic_uint64)resultEDX << 32) | resultEAX;
}
#endif
#else
#if defined(C89ATOMIC_HAS_8)
#define c89atomic_compare_and_swap_8( dst, expected, desired) (c89atomic_uint8 )_InterlockedCompareExchange8((volatile char*)dst, (char)desired, (char)expected)
#endif
#if defined(C89ATOMIC_HAS_16)
#define c89atomic_compare_and_swap_16(dst, expected, desired) (c89atomic_uint16)_InterlockedCompareExchange16((volatile short*)dst, (short)desired, (short)expected)
#endif
#if defined(C89ATOMIC_HAS_32)
#define c89atomic_compare_and_swap_32(dst, expected, desired) (c89atomic_uint32)_InterlockedCompareExchange((volatile long*)dst, (long)desired, (long)expected)
#endif
#if defined(C89ATOMIC_HAS_64)
#define c89atomic_compare_and_swap_64(dst, expected, desired) (c89atomic_uint64)_InterlockedCompareExchange64((volatile long long*)dst, (long long)desired, (long long)expected)
#endif
#endif
#if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
#if defined(C89ATOMIC_HAS_8)
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
{ {
c89atomic_uint8 result = 0; c89atomic_uint8 result = 0;
...@@ -8390,6 +8411,8 @@ typedef unsigned char c89atomic_flag; ...@@ -8390,6 +8411,8 @@ typedef unsigned char c89atomic_flag;
} }
return result; return result;
} }
#endif
#if defined(C89ATOMIC_HAS_16)
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{ {
c89atomic_uint16 result = 0; c89atomic_uint16 result = 0;
...@@ -8402,6 +8425,8 @@ typedef unsigned char c89atomic_flag; ...@@ -8402,6 +8425,8 @@ typedef unsigned char c89atomic_flag;
} }
return result; return result;
} }
#endif
#if defined(C89ATOMIC_HAS_32)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{ {
c89atomic_uint32 result = 0; c89atomic_uint32 result = 0;
...@@ -8414,6 +8439,51 @@ typedef unsigned char c89atomic_flag; ...@@ -8414,6 +8439,51 @@ typedef unsigned char c89atomic_flag;
} }
return result; return result;
} }
#endif
#else
#if defined(C89ATOMIC_HAS_8)
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint8)_InterlockedExchange8((volatile char*)dst, (char)src);
}
#endif
#if defined(C89ATOMIC_HAS_16)
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint16)_InterlockedExchange16((volatile short*)dst, (short)src);
}
#endif
#if defined(C89ATOMIC_HAS_32)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint32)_InterlockedExchange((volatile long*)dst, (long)src);
}
#endif
#if defined(C89ATOMIC_HAS_64) && defined(C89ATOMIC_64BIT)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{
(void)order;
return (c89atomic_uint64)_InterlockedExchange64((volatile long long*)dst, (long long)src);
}
#else
#endif
#endif
#if defined(C89ATOMIC_HAS_64) && !defined(C89ATOMIC_64BIT)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{
volatile c89atomic_uint64 oldValue;
do {
oldValue = *dst;
} while (c89atomic_compare_and_swap_64(dst, oldValue, src) != oldValue);
(void)order;
return oldValue;
}
#endif
#if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
#if defined(C89ATOMIC_HAS_8)
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
{ {
c89atomic_uint8 result = 0; c89atomic_uint8 result = 0;
...@@ -8426,6 +8496,8 @@ typedef unsigned char c89atomic_flag; ...@@ -8426,6 +8496,8 @@ typedef unsigned char c89atomic_flag;
} }
return result; return result;
} }
#endif
#if defined(C89ATOMIC_HAS_16)
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{ {
c89atomic_uint16 result = 0; c89atomic_uint16 result = 0;
...@@ -8438,6 +8510,8 @@ typedef unsigned char c89atomic_flag; ...@@ -8438,6 +8510,8 @@ typedef unsigned char c89atomic_flag;
} }
return result; return result;
} }
#endif
#if defined(C89ATOMIC_HAS_32)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{ {
c89atomic_uint32 result = 0; c89atomic_uint32 result = 0;
...@@ -8450,314 +8524,371 @@ typedef unsigned char c89atomic_flag; ...@@ -8450,314 +8524,371 @@ typedef unsigned char c89atomic_flag;
} }
return result; return result;
} }
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_compare_and_swap_8(volatile c89atomic_uint8* dst, c89atomic_uint8 expected, c89atomic_uint8 desired) #endif
#else
#if defined(C89ATOMIC_HAS_8)
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
{ {
c89atomic_uint8 result = 0; (void)order;
__asm { return (c89atomic_uint8)_InterlockedExchangeAdd8((volatile char*)dst, (char)src);
mov ecx, dst
mov al, expected
mov dl, desired
lock cmpxchg [ecx], dl
mov result, al
}
return result;
} }
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_compare_and_swap_16(volatile c89atomic_uint16* dst, c89atomic_uint16 expected, c89atomic_uint16 desired) #endif
#if defined(C89ATOMIC_HAS_16)
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{ {
c89atomic_uint16 result = 0; (void)order;
__asm { return (c89atomic_uint16)_InterlockedExchangeAdd16((volatile short*)dst, (short)src);
mov ecx, dst
mov ax, expected
mov dx, desired
lock cmpxchg [ecx], dx
mov result, ax
}
return result;
} }
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_compare_and_swap_32(volatile c89atomic_uint32* dst, c89atomic_uint32 expected, c89atomic_uint32 desired) #endif
#if defined(C89ATOMIC_HAS_32)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{ {
c89atomic_uint32 result = 0; (void)order;
__asm { return (c89atomic_uint32)_InterlockedExchangeAdd((volatile long*)dst, (long)src);
mov ecx, dst
mov eax, expected
mov edx, desired
lock cmpxchg [ecx], edx
mov result, eax
}
return result;
} }
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_compare_and_swap_64(volatile c89atomic_uint64* dst, c89atomic_uint64 expected, c89atomic_uint64 desired) #endif
#if defined(C89ATOMIC_HAS_64) && defined(C89ATOMIC_64BIT)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{ {
c89atomic_uint32 resultEAX = 0; (void)order;
c89atomic_uint32 resultEDX = 0; return (c89atomic_uint64)_InterlockedExchangeAdd64((volatile long long*)dst, (long long)src);
__asm {
mov esi, dst
mov eax, dword ptr expected
mov edx, dword ptr expected + 4
mov ebx, dword ptr desired
mov ecx, dword ptr desired + 4
lock cmpxchg8b qword ptr [esi]
mov resultEAX, eax
mov resultEDX, edx
}
return ((c89atomic_uint64)resultEDX << 32) | resultEAX;
} }
#else #else
#error Unsupported architecture.
#endif #endif
#endif #endif
#define c89atomic_compiler_fence() c89atomic_thread_fence(c89atomic_memory_order_seq_cst) #if defined(C89ATOMIC_HAS_64) && !defined(C89ATOMIC_64BIT)
#define c89atomic_signal_fence(order) c89atomic_thread_fence(order) static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_load_explicit_8(volatile c89atomic_uint8* ptr, c89atomic_memory_order order) {
{ volatile c89atomic_uint64 oldValue;
(void)order; volatile c89atomic_uint64 newValue;
return c89atomic_compare_and_swap_8(ptr, 0, 0); do {
} oldValue = *dst;
static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_load_explicit_16(volatile c89atomic_uint16* ptr, c89atomic_memory_order order) newValue = oldValue + src;
{ } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order; (void)order;
return c89atomic_compare_and_swap_16(ptr, 0, 0); return oldValue;
} }
static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_load_explicit_32(volatile c89atomic_uint32* ptr, c89atomic_memory_order order) #endif
{ #if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
(void)order; static C89ATOMIC_INLINE void __stdcall c89atomic_thread_fence(c89atomic_memory_order order)
return c89atomic_compare_and_swap_32(ptr, 0, 0); {
} (void)order;
static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_load_explicit_64(volatile c89atomic_uint64* ptr, c89atomic_memory_order order) __asm {
{ lock add [esp], 0
(void)order; }
return c89atomic_compare_and_swap_64(ptr, 0, 0); }
} #else
#define c89atomic_store_explicit_8( dst, src, order) (void)c89atomic_exchange_explicit_8 (dst, src, order) #if defined(C89ATOMIC_X64)
#define c89atomic_store_explicit_16(dst, src, order) (void)c89atomic_exchange_explicit_16(dst, src, order) #define c89atomic_thread_fence(order) __faststorefence(), (void)order
#define c89atomic_store_explicit_32(dst, src, order) (void)c89atomic_exchange_explicit_32(dst, src, order) #else
#define c89atomic_store_explicit_64(dst, src, order) (void)c89atomic_exchange_explicit_64(dst, src, order) static C89ATOMIC_INLINE void c89atomic_thread_fence(c89atomic_memory_order order)
#if defined(C89ATOMIC_32BIT) {
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order) volatile c89atomic_uint32 barrier = 0;
{ c89atomic_fetch_add_explicit_32(&barrier, 0, order);
volatile c89atomic_uint64 oldValue; }
do { #endif
oldValue = *dst; #endif
} while (c89atomic_compare_and_swap_64(dst, oldValue, src) != oldValue); #define c89atomic_compiler_fence() c89atomic_thread_fence(c89atomic_memory_order_seq_cst)
(void)order; #define c89atomic_signal_fence(order) c89atomic_thread_fence(order)
return oldValue; #if defined(C89ATOMIC_HAS_8)
} static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_load_explicit_8(volatile c89atomic_uint8* ptr, c89atomic_memory_order order)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order) {
{ (void)order;
volatile c89atomic_uint64 oldValue; return c89atomic_compare_and_swap_8(ptr, 0, 0);
volatile c89atomic_uint64 newValue; }
do { #endif
oldValue = *dst; #if defined(C89ATOMIC_HAS_16)
newValue = oldValue + src; static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_load_explicit_16(volatile c89atomic_uint16* ptr, c89atomic_memory_order order)
} while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue); {
(void)order; (void)order;
return oldValue; return c89atomic_compare_and_swap_16(ptr, 0, 0);
} }
#endif #endif
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) #if defined(C89ATOMIC_HAS_32)
{ static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_load_explicit_32(volatile c89atomic_uint32* ptr, c89atomic_memory_order order)
volatile c89atomic_uint8 oldValue; {
volatile c89atomic_uint8 newValue; (void)order;
do { return c89atomic_compare_and_swap_32(ptr, 0, 0);
oldValue = *dst; }
newValue = (c89atomic_uint8)(oldValue - src); #endif
} while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue); #if defined(C89ATOMIC_HAS_64)
(void)order; static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_load_explicit_64(volatile c89atomic_uint64* ptr, c89atomic_memory_order order)
return oldValue; {
} (void)order;
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order) return c89atomic_compare_and_swap_64(ptr, 0, 0);
{ }
volatile c89atomic_uint16 oldValue; #endif
volatile c89atomic_uint16 newValue; #if defined(C89ATOMIC_HAS_8)
do { #define c89atomic_store_explicit_8( dst, src, order) (void)c89atomic_exchange_explicit_8 (dst, src, order)
oldValue = *dst; #endif
newValue = (c89atomic_uint16)(oldValue - src); #if defined(C89ATOMIC_HAS_16)
} while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue); #define c89atomic_store_explicit_16(dst, src, order) (void)c89atomic_exchange_explicit_16(dst, src, order)
(void)order; #endif
return oldValue; #if defined(C89ATOMIC_HAS_32)
} #define c89atomic_store_explicit_32(dst, src, order) (void)c89atomic_exchange_explicit_32(dst, src, order)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_sub_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order) #endif
{ #if defined(C89ATOMIC_HAS_64)
volatile c89atomic_uint32 oldValue; #define c89atomic_store_explicit_64(dst, src, order) (void)c89atomic_exchange_explicit_64(dst, src, order)
volatile c89atomic_uint32 newValue; #endif
do { #if defined(C89ATOMIC_HAS_8)
oldValue = *dst; static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
newValue = oldValue - src; {
} while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue); volatile c89atomic_uint8 oldValue;
(void)order; volatile c89atomic_uint8 newValue;
return oldValue; do {
} oldValue = *dst;
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_sub_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order) newValue = (c89atomic_uint8)(oldValue - src);
{ } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
volatile c89atomic_uint64 oldValue; (void)order;
volatile c89atomic_uint64 newValue; return oldValue;
do { }
oldValue = *dst; #endif
newValue = oldValue - src; #if defined(C89ATOMIC_HAS_16)
} while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue); static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
(void)order; {
return oldValue; volatile c89atomic_uint16 oldValue;
} volatile c89atomic_uint16 newValue;
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) do {
{ oldValue = *dst;
volatile c89atomic_uint8 oldValue; newValue = (c89atomic_uint16)(oldValue - src);
volatile c89atomic_uint8 newValue; } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
do { (void)order;
oldValue = *dst; return oldValue;
newValue = (c89atomic_uint8)(oldValue & src); }
} while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue); #endif
(void)order; #if defined(C89ATOMIC_HAS_32)
return oldValue; static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_sub_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
} {
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_and_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order) volatile c89atomic_uint32 oldValue;
{ volatile c89atomic_uint32 newValue;
volatile c89atomic_uint16 oldValue; do {
volatile c89atomic_uint16 newValue; oldValue = *dst;
do { newValue = oldValue - src;
oldValue = *dst; } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
newValue = (c89atomic_uint16)(oldValue & src); (void)order;
} while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue); return oldValue;
(void)order; }
return oldValue; #endif
} #if defined(C89ATOMIC_HAS_64)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_and_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order) static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_sub_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{ {
volatile c89atomic_uint32 oldValue; volatile c89atomic_uint64 oldValue;
volatile c89atomic_uint32 newValue; volatile c89atomic_uint64 newValue;
do { do {
oldValue = *dst; oldValue = *dst;
newValue = oldValue & src; newValue = oldValue - src;
} while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue); } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order; (void)order;
return oldValue; return oldValue;
} }
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order) #endif
{ #if defined(C89ATOMIC_HAS_8)
volatile c89atomic_uint64 oldValue; static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
volatile c89atomic_uint64 newValue; {
do { volatile c89atomic_uint8 oldValue;
oldValue = *dst; volatile c89atomic_uint8 newValue;
newValue = oldValue & src; do {
} while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue); oldValue = *dst;
(void)order; newValue = (c89atomic_uint8)(oldValue & src);
return oldValue; } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
} (void)order;
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_xor_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) return oldValue;
{ }
volatile c89atomic_uint8 oldValue; #endif
volatile c89atomic_uint8 newValue; #if defined(C89ATOMIC_HAS_16)
do { static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_and_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
oldValue = *dst; {
newValue = (c89atomic_uint8)(oldValue ^ src); volatile c89atomic_uint16 oldValue;
} while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue); volatile c89atomic_uint16 newValue;
(void)order; do {
return oldValue; oldValue = *dst;
} newValue = (c89atomic_uint16)(oldValue & src);
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_xor_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order) } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
{ (void)order;
volatile c89atomic_uint16 oldValue; return oldValue;
volatile c89atomic_uint16 newValue; }
do { #endif
oldValue = *dst; #if defined(C89ATOMIC_HAS_32)
newValue = (c89atomic_uint16)(oldValue ^ src); static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_and_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
} while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue); {
(void)order; volatile c89atomic_uint32 oldValue;
return oldValue; volatile c89atomic_uint32 newValue;
} do {
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order) oldValue = *dst;
{ newValue = oldValue & src;
volatile c89atomic_uint32 oldValue; } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
volatile c89atomic_uint32 newValue; (void)order;
do { return oldValue;
oldValue = *dst; }
newValue = oldValue ^ src; #endif
} while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue); #if defined(C89ATOMIC_HAS_64)
(void)order; static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
return oldValue; {
} volatile c89atomic_uint64 oldValue;
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_xor_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order) volatile c89atomic_uint64 newValue;
{ do {
volatile c89atomic_uint64 oldValue; oldValue = *dst;
volatile c89atomic_uint64 newValue; newValue = oldValue & src;
do { } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
oldValue = *dst; (void)order;
newValue = oldValue ^ src; return oldValue;
} while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue); }
(void)order; #endif
return oldValue; #if defined(C89ATOMIC_HAS_8)
} static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_xor_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_or_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order) {
{ volatile c89atomic_uint8 oldValue;
volatile c89atomic_uint8 oldValue; volatile c89atomic_uint8 newValue;
volatile c89atomic_uint8 newValue; do {
do { oldValue = *dst;
oldValue = *dst; newValue = (c89atomic_uint8)(oldValue ^ src);
newValue = (c89atomic_uint8)(oldValue | src); } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
} while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue); (void)order;
(void)order; return oldValue;
return oldValue; }
} #endif
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_or_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order) #if defined(C89ATOMIC_HAS_16)
{ static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_xor_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
volatile c89atomic_uint16 oldValue; {
volatile c89atomic_uint16 newValue; volatile c89atomic_uint16 oldValue;
do { volatile c89atomic_uint16 newValue;
oldValue = *dst; do {
newValue = (c89atomic_uint16)(oldValue | src); oldValue = *dst;
} while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue); newValue = (c89atomic_uint16)(oldValue ^ src);
(void)order; } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
return oldValue; (void)order;
} return oldValue;
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_or_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order) }
{ #endif
volatile c89atomic_uint32 oldValue; #if defined(C89ATOMIC_HAS_32)
volatile c89atomic_uint32 newValue; static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
do { {
oldValue = *dst; volatile c89atomic_uint32 oldValue;
newValue = oldValue | src; volatile c89atomic_uint32 newValue;
} while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue); do {
(void)order; oldValue = *dst;
return oldValue; newValue = oldValue ^ src;
} } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_or_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order) (void)order;
{ return oldValue;
volatile c89atomic_uint64 oldValue; }
volatile c89atomic_uint64 newValue; #endif
do { #if defined(C89ATOMIC_HAS_64)
oldValue = *dst; static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_xor_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
newValue = oldValue | src; {
} while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue); volatile c89atomic_uint64 oldValue;
(void)order; volatile c89atomic_uint64 newValue;
return oldValue; do {
} oldValue = *dst;
#define c89atomic_test_and_set_explicit_8( dst, order) c89atomic_exchange_explicit_8 (dst, 1, order) newValue = oldValue ^ src;
#define c89atomic_test_and_set_explicit_16(dst, order) c89atomic_exchange_explicit_16(dst, 1, order) } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
#define c89atomic_test_and_set_explicit_32(dst, order) c89atomic_exchange_explicit_32(dst, 1, order) (void)order;
#define c89atomic_test_and_set_explicit_64(dst, order) c89atomic_exchange_explicit_64(dst, 1, order) return oldValue;
#define c89atomic_clear_explicit_8( dst, order) c89atomic_store_explicit_8 (dst, 0, order) }
#define c89atomic_clear_explicit_16(dst, order) c89atomic_store_explicit_16(dst, 0, order) #endif
#define c89atomic_clear_explicit_32(dst, order) c89atomic_store_explicit_32(dst, 0, order) #if defined(C89ATOMIC_HAS_8)
#define c89atomic_clear_explicit_64(dst, order) c89atomic_store_explicit_64(dst, 0, order) static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_or_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
#define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_flag)c89atomic_test_and_set_explicit_8(ptr, order) {
#define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_8(ptr, order) volatile c89atomic_uint8 oldValue;
volatile c89atomic_uint8 newValue;
do {
oldValue = *dst;
newValue = (c89atomic_uint8)(oldValue | src);
} while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
#if defined(C89ATOMIC_HAS_16)
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_or_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
{
volatile c89atomic_uint16 oldValue;
volatile c89atomic_uint16 newValue;
do {
oldValue = *dst;
newValue = (c89atomic_uint16)(oldValue | src);
} while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
#if defined(C89ATOMIC_HAS_32)
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_or_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
{
volatile c89atomic_uint32 oldValue;
volatile c89atomic_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue | src;
} while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
#if defined(C89ATOMIC_HAS_64)
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_or_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
{
volatile c89atomic_uint64 oldValue;
volatile c89atomic_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue | src;
} while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
#if defined(C89ATOMIC_HAS_8)
#define c89atomic_test_and_set_explicit_8( dst, order) c89atomic_exchange_explicit_8 (dst, 1, order)
#endif
#if defined(C89ATOMIC_HAS_16)
#define c89atomic_test_and_set_explicit_16(dst, order) c89atomic_exchange_explicit_16(dst, 1, order)
#endif
#if defined(C89ATOMIC_HAS_32)
#define c89atomic_test_and_set_explicit_32(dst, order) c89atomic_exchange_explicit_32(dst, 1, order)
#endif
#if defined(C89ATOMIC_HAS_64)
#define c89atomic_test_and_set_explicit_64(dst, order) c89atomic_exchange_explicit_64(dst, 1, order)
#endif
#if defined(C89ATOMIC_HAS_8)
#define c89atomic_clear_explicit_8( dst, order) c89atomic_store_explicit_8 (dst, 0, order)
#endif
#if defined(C89ATOMIC_HAS_16)
#define c89atomic_clear_explicit_16(dst, order) c89atomic_store_explicit_16(dst, 0, order)
#endif
#if defined(C89ATOMIC_HAS_32)
#define c89atomic_clear_explicit_32(dst, order) c89atomic_store_explicit_32(dst, 0, order)
#endif
#if defined(C89ATOMIC_HAS_64)
#define c89atomic_clear_explicit_64(dst, order) c89atomic_store_explicit_64(dst, 0, order)
#endif
#if defined(C89ATOMIC_HAS_8)
typedef c89atomic_uint8 c89atomic_flag;
#define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_bool)c89atomic_test_and_set_explicit_8(ptr, order)
#define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_8(ptr, order)
#define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_8(ptr, order)
#else
typedef c89atomic_uint32 c89atomic_flag;
#define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_bool)c89atomic_test_and_set_explicit_32(ptr, order)
#define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_32(ptr, order)
#define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_32(ptr, order)
#endif
#elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) #elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))
#define C89ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE #define C89ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE
#define C89ATOMIC_HAS_NATIVE_IS_LOCK_FREE #define C89ATOMIC_HAS_NATIVE_IS_LOCK_FREE
#define c89atomic_memory_order_relaxed __ATOMIC_RELAXED #define c89atomic_memory_order_relaxed __ATOMIC_RELAXED
#define c89atomic_memory_order_consume __ATOMIC_CONSUME #define c89atomic_memory_order_consume __ATOMIC_CONSUME
#define c89atomic_memory_order_acquire __ATOMIC_ACQUIRE #define c89atomic_memory_order_acquire __ATOMIC_ACQUIRE
#define c89atomic_memory_order_release __ATOMIC_RELEASE #define c89atomic_memory_order_release __ATOMIC_RELEASE
#define c89atomic_memory_order_acq_rel __ATOMIC_ACQ_REL #define c89atomic_memory_order_acq_rel __ATOMIC_ACQ_REL
#define c89atomic_memory_order_seq_cst __ATOMIC_SEQ_CST #define c89atomic_memory_order_seq_cst __ATOMIC_SEQ_CST
#define c89atomic_compiler_fence() __asm__ __volatile__("":::"memory") #define c89atomic_compiler_fence() __asm__ __volatile__("":::"memory")
#define c89atomic_thread_fence(order) __atomic_thread_fence(order) #define c89atomic_thread_fence(order) __atomic_thread_fence(order)
#define c89atomic_signal_fence(order) __atomic_signal_fence(order) #define c89atomic_signal_fence(order) __atomic_signal_fence(order)
#define c89atomic_is_lock_free_8(ptr) __atomic_is_lock_free(1, ptr) #define c89atomic_is_lock_free_8(ptr) __atomic_is_lock_free(1, ptr)
#define c89atomic_is_lock_free_16(ptr) __atomic_is_lock_free(2, ptr) #define c89atomic_is_lock_free_16(ptr) __atomic_is_lock_free(2, ptr)
#define c89atomic_is_lock_free_32(ptr) __atomic_is_lock_free(4, ptr) #define c89atomic_is_lock_free_32(ptr) __atomic_is_lock_free(4, ptr)
#define c89atomic_is_lock_free_64(ptr) __atomic_is_lock_free(8, ptr) #define c89atomic_is_lock_free_64(ptr) __atomic_is_lock_free(8, ptr)
#define c89atomic_flag_test_and_set_explicit(dst, order) (c89atomic_flag)__atomic_test_and_set(dst, order)
#define c89atomic_flag_clear_explicit(dst, order) __atomic_clear(dst, order)
#define c89atomic_test_and_set_explicit_8( dst, order) __atomic_exchange_n(dst, 1, order) #define c89atomic_test_and_set_explicit_8( dst, order) __atomic_exchange_n(dst, 1, order)
#define c89atomic_test_and_set_explicit_16(dst, order) __atomic_exchange_n(dst, 1, order) #define c89atomic_test_and_set_explicit_16(dst, order) __atomic_exchange_n(dst, 1, order)
#define c89atomic_test_and_set_explicit_32(dst, order) __atomic_exchange_n(dst, 1, order) #define c89atomic_test_and_set_explicit_32(dst, order) __atomic_exchange_n(dst, 1, order)
...@@ -8810,6 +8941,10 @@ typedef unsigned char c89atomic_flag; ...@@ -8810,6 +8941,10 @@ typedef unsigned char c89atomic_flag;
#define c89atomic_compare_and_swap_16(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired) #define c89atomic_compare_and_swap_16(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
#define c89atomic_compare_and_swap_32(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired) #define c89atomic_compare_and_swap_32(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
#define c89atomic_compare_and_swap_64(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired) #define c89atomic_compare_and_swap_64(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
typedef c89atomic_uint8 c89atomic_flag;
#define c89atomic_flag_test_and_set_explicit(dst, order) (c89atomic_bool)__atomic_test_and_set(dst, order)
#define c89atomic_flag_clear_explicit(dst, order) __atomic_clear(dst, order)
#define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_8(ptr, order)
#else #else
#define c89atomic_memory_order_relaxed 1 #define c89atomic_memory_order_relaxed 1
#define c89atomic_memory_order_consume 2 #define c89atomic_memory_order_consume 2
...@@ -9320,74 +9455,84 @@ typedef unsigned char c89atomic_flag; ...@@ -9320,74 +9455,84 @@ typedef unsigned char c89atomic_flag;
#define c89atomic_clear_explicit_16(dst, order) c89atomic_store_explicit_16(dst, 0, order) #define c89atomic_clear_explicit_16(dst, order) c89atomic_store_explicit_16(dst, 0, order)
#define c89atomic_clear_explicit_32(dst, order) c89atomic_store_explicit_32(dst, 0, order) #define c89atomic_clear_explicit_32(dst, order) c89atomic_store_explicit_32(dst, 0, order)
#define c89atomic_clear_explicit_64(dst, order) c89atomic_store_explicit_64(dst, 0, order) #define c89atomic_clear_explicit_64(dst, order) c89atomic_store_explicit_64(dst, 0, order)
#define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_flag)c89atomic_test_and_set_explicit_8(ptr, order) typedef c89atomic_uint8 c89atomic_flag;
#define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_bool)c89atomic_test_and_set_explicit_8(ptr, order)
#define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_8(ptr, order) #define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_8(ptr, order)
#define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_8(ptr, order)
#endif #endif
#if !defined(C89ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE) #if !defined(C89ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE)
c89atomic_bool c89atomic_compare_exchange_strong_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8* expected, c89atomic_uint8 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder) #if defined(C89ATOMIC_HAS_8)
{ c89atomic_bool c89atomic_compare_exchange_strong_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8* expected, c89atomic_uint8 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
c89atomic_uint8 expectedValue; {
c89atomic_uint8 result; c89atomic_uint8 expectedValue;
(void)successOrder; c89atomic_uint8 result;
(void)failureOrder; (void)successOrder;
expectedValue = c89atomic_load_explicit_8(expected, c89atomic_memory_order_seq_cst); (void)failureOrder;
result = c89atomic_compare_and_swap_8(dst, expectedValue, desired); expectedValue = c89atomic_load_explicit_8(expected, c89atomic_memory_order_seq_cst);
if (result == expectedValue) { result = c89atomic_compare_and_swap_8(dst, expectedValue, desired);
return 1; if (result == expectedValue) {
} else { return 1;
c89atomic_store_explicit_8(expected, result, failureOrder); } else {
return 0; c89atomic_store_explicit_8(expected, result, failureOrder);
} return 0;
} }
c89atomic_bool c89atomic_compare_exchange_strong_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16* expected, c89atomic_uint16 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder) }
{ #endif
c89atomic_uint16 expectedValue; #if defined(C89ATOMIC_HAS_16)
c89atomic_uint16 result; c89atomic_bool c89atomic_compare_exchange_strong_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16* expected, c89atomic_uint16 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
(void)successOrder; {
(void)failureOrder; c89atomic_uint16 expectedValue;
expectedValue = c89atomic_load_explicit_16(expected, c89atomic_memory_order_seq_cst); c89atomic_uint16 result;
result = c89atomic_compare_and_swap_16(dst, expectedValue, desired); (void)successOrder;
if (result == expectedValue) { (void)failureOrder;
return 1; expectedValue = c89atomic_load_explicit_16(expected, c89atomic_memory_order_seq_cst);
} else { result = c89atomic_compare_and_swap_16(dst, expectedValue, desired);
c89atomic_store_explicit_16(expected, result, failureOrder); if (result == expectedValue) {
return 0; return 1;
} } else {
} c89atomic_store_explicit_16(expected, result, failureOrder);
c89atomic_bool c89atomic_compare_exchange_strong_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32* expected, c89atomic_uint32 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder) return 0;
{ }
c89atomic_uint32 expectedValue; }
c89atomic_uint32 result; #endif
(void)successOrder; #if defined(C89ATOMIC_HAS_32)
(void)failureOrder; c89atomic_bool c89atomic_compare_exchange_strong_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32* expected, c89atomic_uint32 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
expectedValue = c89atomic_load_explicit_32(expected, c89atomic_memory_order_seq_cst); {
result = c89atomic_compare_and_swap_32(dst, expectedValue, desired); c89atomic_uint32 expectedValue;
if (result == expectedValue) { c89atomic_uint32 result;
return 1; (void)successOrder;
} else { (void)failureOrder;
c89atomic_store_explicit_32(expected, result, failureOrder); expectedValue = c89atomic_load_explicit_32(expected, c89atomic_memory_order_seq_cst);
return 0; result = c89atomic_compare_and_swap_32(dst, expectedValue, desired);
} if (result == expectedValue) {
} return 1;
c89atomic_bool c89atomic_compare_exchange_strong_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64* expected, c89atomic_uint64 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder) } else {
{ c89atomic_store_explicit_32(expected, result, failureOrder);
c89atomic_uint64 expectedValue; return 0;
c89atomic_uint64 result; }
(void)successOrder; }
(void)failureOrder; #endif
expectedValue = c89atomic_load_explicit_64(expected, c89atomic_memory_order_seq_cst); #if defined(C89ATOMIC_HAS_64)
result = c89atomic_compare_and_swap_64(dst, expectedValue, desired); c89atomic_bool c89atomic_compare_exchange_strong_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64* expected, c89atomic_uint64 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
if (result == expectedValue) { {
return 1; c89atomic_uint64 expectedValue;
} else { c89atomic_uint64 result;
c89atomic_store_explicit_64(expected, result, failureOrder); (void)successOrder;
return 0; (void)failureOrder;
} expectedValue = c89atomic_load_explicit_64(expected, c89atomic_memory_order_seq_cst);
} result = c89atomic_compare_and_swap_64(dst, expectedValue, desired);
#define c89atomic_compare_exchange_weak_explicit_8( dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_8 (dst, expected, desired, successOrder, failureOrder) if (result == expectedValue) {
#define c89atomic_compare_exchange_weak_explicit_16(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_16(dst, expected, desired, successOrder, failureOrder) return 1;
#define c89atomic_compare_exchange_weak_explicit_32(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder) } else {
#define c89atomic_compare_exchange_weak_explicit_64(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_64(dst, expected, desired, successOrder, failureOrder) c89atomic_store_explicit_64(expected, result, failureOrder);
return 0;
}
}
#endif
#define c89atomic_compare_exchange_weak_explicit_8( dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_8 (dst, expected, desired, successOrder, failureOrder)
#define c89atomic_compare_exchange_weak_explicit_16(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_16(dst, expected, desired, successOrder, failureOrder)
#define c89atomic_compare_exchange_weak_explicit_32(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder)
#define c89atomic_compare_exchange_weak_explicit_64(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_64(dst, expected, desired, successOrder, failureOrder)
#endif #endif
#if !defined(C89ATOMIC_HAS_NATIVE_IS_LOCK_FREE) #if !defined(C89ATOMIC_HAS_NATIVE_IS_LOCK_FREE)
static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_8(volatile void* ptr) static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_8(volatile void* ptr)
...@@ -9698,7 +9843,7 @@ static C89ATOMIC_INLINE void c89atomic_spinlock_lock(volatile c89atomic_spinlock ...@@ -9698,7 +9843,7 @@ static C89ATOMIC_INLINE void c89atomic_spinlock_lock(volatile c89atomic_spinlock
if (c89atomic_flag_test_and_set_explicit(pSpinlock, c89atomic_memory_order_acquire) == 0) { if (c89atomic_flag_test_and_set_explicit(pSpinlock, c89atomic_memory_order_acquire) == 0) {
break; break;
} }
while (c89atomic_load_explicit_8(pSpinlock, c89atomic_memory_order_relaxed) == 1) { while (c89atoimc_flag_load_explicit(pSpinlock, c89atomic_memory_order_relaxed) == 1) {
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment