mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
Update c89atomic.
This commit is contained in:
+306
-161
@@ -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;
|
|||||||
#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,147 +8312,18 @@ 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)
|
||||||
|
#define C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY
|
||||||
|
#endif
|
||||||
|
#if _MSC_VER < 1600
|
||||||
|
#undef C89ATOMIC_HAS_8
|
||||||
|
#undef C89ATOMIC_HAS_16
|
||||||
|
#endif
|
||||||
|
#if !defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
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 defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
|
||||||
{
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
(void)order;
|
|
||||||
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
|
|
||||||
#define c89atomic_compare_and_swap_8( dst, expected, desired) (c89atomic_uint8 )_InterlockedCompareExchange8 ((volatile char* )dst, (char )desired, (char )expected)
|
|
||||||
#define c89atomic_compare_and_swap_16(dst, expected, desired) (c89atomic_uint16)_InterlockedCompareExchange16((volatile short* )dst, (short )desired, (short )expected)
|
|
||||||
#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
|
|
||||||
#else
|
|
||||||
#if defined(C89ATOMIC_X86)
|
|
||||||
static C89ATOMIC_INLINE void __stdcall c89atomic_thread_fence(c89atomic_memory_order order)
|
|
||||||
{
|
|
||||||
(void)order;
|
|
||||||
__asm {
|
|
||||||
lock add [esp], 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
(void)order;
|
|
||||||
__asm {
|
|
||||||
mov ecx, dst
|
|
||||||
mov al, src
|
|
||||||
lock xchg [ecx], al
|
|
||||||
mov result, al
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
(void)order;
|
|
||||||
__asm {
|
|
||||||
mov ecx, dst
|
|
||||||
mov ax, src
|
|
||||||
lock xchg [ecx], ax
|
|
||||||
mov result, ax
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
(void)order;
|
|
||||||
__asm {
|
|
||||||
mov ecx, dst
|
|
||||||
mov eax, src
|
|
||||||
lock xchg [ecx], eax
|
|
||||||
mov result, eax
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
mov ecx, dst
|
|
||||||
mov al, src
|
|
||||||
lock xadd [ecx], al
|
|
||||||
mov result, al
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
mov ecx, dst
|
|
||||||
mov ax, src
|
|
||||||
lock xadd [ecx], ax
|
|
||||||
mov result, ax
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
mov ecx, dst
|
|
||||||
mov eax, src
|
|
||||||
lock xadd [ecx], eax
|
|
||||||
mov result, eax
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_compare_and_swap_8(volatile c89atomic_uint8* dst, c89atomic_uint8 expected, c89atomic_uint8 desired)
|
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_compare_and_swap_8(volatile c89atomic_uint8* dst, c89atomic_uint8 expected, c89atomic_uint8 desired)
|
||||||
{
|
{
|
||||||
c89atomic_uint8 result = 0;
|
c89atomic_uint8 result = 0;
|
||||||
@@ -8462,6 +8336,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
}
|
}
|
||||||
return result;
|
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)
|
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;
|
c89atomic_uint16 result = 0;
|
||||||
@@ -8474,6 +8350,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
}
|
}
|
||||||
return result;
|
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)
|
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;
|
c89atomic_uint32 result = 0;
|
||||||
@@ -8486,6 +8364,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
}
|
}
|
||||||
return result;
|
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)
|
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 resultEAX = 0;
|
||||||
@@ -8502,37 +8382,96 @@ typedef unsigned char c89atomic_flag;
|
|||||||
}
|
}
|
||||||
return ((c89atomic_uint64)resultEDX << 32) | resultEAX;
|
return ((c89atomic_uint64)resultEDX << 32) | resultEAX;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#error Unsupported architecture.
|
#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
|
||||||
#endif
|
#endif
|
||||||
#define c89atomic_compiler_fence() c89atomic_thread_fence(c89atomic_memory_order_seq_cst)
|
#if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
|
||||||
#define c89atomic_signal_fence(order) c89atomic_thread_fence(order)
|
#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_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
|
||||||
|
{
|
||||||
|
c89atomic_uint8 result = 0;
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
mov ecx, dst
|
||||||
|
mov al, src
|
||||||
|
lock xchg [ecx], al
|
||||||
|
mov result, al
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
c89atomic_uint16 result = 0;
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
mov ecx, dst
|
||||||
|
mov ax, src
|
||||||
|
lock xchg [ecx], ax
|
||||||
|
mov result, ax
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
c89atomic_uint32 result = 0;
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
mov ecx, dst
|
||||||
|
mov eax, src
|
||||||
|
lock xchg [ecx], eax
|
||||||
|
mov result, eax
|
||||||
|
}
|
||||||
|
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;
|
(void)order;
|
||||||
return c89atomic_compare_and_swap_8(ptr, 0, 0);
|
return (c89atomic_uint8)_InterlockedExchange8((volatile char*)dst, (char)src);
|
||||||
}
|
}
|
||||||
static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_load_explicit_16(volatile c89atomic_uint16* ptr, c89atomic_memory_order order)
|
#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;
|
(void)order;
|
||||||
return c89atomic_compare_and_swap_16(ptr, 0, 0);
|
return (c89atomic_uint16)_InterlockedExchange16((volatile short*)dst, (short)src);
|
||||||
}
|
}
|
||||||
static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_load_explicit_32(volatile c89atomic_uint32* ptr, c89atomic_memory_order order)
|
#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;
|
(void)order;
|
||||||
return c89atomic_compare_and_swap_32(ptr, 0, 0);
|
return (c89atomic_uint32)_InterlockedExchange((volatile long*)dst, (long)src);
|
||||||
}
|
}
|
||||||
static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_load_explicit_64(volatile c89atomic_uint64* ptr, c89atomic_memory_order order)
|
#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;
|
(void)order;
|
||||||
return c89atomic_compare_and_swap_64(ptr, 0, 0);
|
return (c89atomic_uint64)_InterlockedExchange64((volatile long long*)dst, (long long)src);
|
||||||
}
|
}
|
||||||
#define c89atomic_store_explicit_8( dst, src, order) (void)c89atomic_exchange_explicit_8 (dst, src, order)
|
#else
|
||||||
#define c89atomic_store_explicit_16(dst, src, order) (void)c89atomic_exchange_explicit_16(dst, src, order)
|
#endif
|
||||||
#define c89atomic_store_explicit_32(dst, src, order) (void)c89atomic_exchange_explicit_32(dst, src, order)
|
#endif
|
||||||
#define c89atomic_store_explicit_64(dst, src, order) (void)c89atomic_exchange_explicit_64(dst, src, order)
|
#if defined(C89ATOMIC_HAS_64) && !defined(C89ATOMIC_64BIT)
|
||||||
#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)
|
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;
|
volatile c89atomic_uint64 oldValue;
|
||||||
@@ -8542,6 +8481,82 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
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)
|
||||||
|
{
|
||||||
|
c89atomic_uint8 result = 0;
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
mov ecx, dst
|
||||||
|
mov al, src
|
||||||
|
lock xadd [ecx], al
|
||||||
|
mov result, al
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
c89atomic_uint16 result = 0;
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
mov ecx, dst
|
||||||
|
mov ax, src
|
||||||
|
lock xadd [ecx], ax
|
||||||
|
mov result, ax
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
c89atomic_uint32 result = 0;
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
mov ecx, dst
|
||||||
|
mov eax, src
|
||||||
|
lock xadd [ecx], eax
|
||||||
|
mov result, eax
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return (c89atomic_uint8)_InterlockedExchangeAdd8((volatile char*)dst, (char)src);
|
||||||
|
}
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return (c89atomic_uint16)_InterlockedExchangeAdd16((volatile short*)dst, (short)src);
|
||||||
|
}
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return (c89atomic_uint32)_InterlockedExchangeAdd((volatile long*)dst, (long)src);
|
||||||
|
}
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return (c89atomic_uint64)_InterlockedExchangeAdd64((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_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, 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)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint64 oldValue;
|
volatile c89atomic_uint64 oldValue;
|
||||||
@@ -8554,6 +8569,68 @@ typedef unsigned char c89atomic_flag;
|
|||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
|
||||||
|
static C89ATOMIC_INLINE void __stdcall c89atomic_thread_fence(c89atomic_memory_order order)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
__asm {
|
||||||
|
lock add [esp], 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#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;
|
||||||
|
c89atomic_fetch_add_explicit_32(&barrier, 0, order);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#define c89atomic_compiler_fence() c89atomic_thread_fence(c89atomic_memory_order_seq_cst)
|
||||||
|
#define c89atomic_signal_fence(order) c89atomic_thread_fence(order)
|
||||||
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
|
static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_load_explicit_8(volatile c89atomic_uint8* ptr, c89atomic_memory_order order)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return c89atomic_compare_and_swap_8(ptr, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_16)
|
||||||
|
static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_load_explicit_16(volatile c89atomic_uint16* ptr, c89atomic_memory_order order)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return c89atomic_compare_and_swap_16(ptr, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_32)
|
||||||
|
static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_load_explicit_32(volatile c89atomic_uint32* ptr, c89atomic_memory_order order)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return c89atomic_compare_and_swap_32(ptr, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_64)
|
||||||
|
static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_load_explicit_64(volatile c89atomic_uint64* ptr, c89atomic_memory_order order)
|
||||||
|
{
|
||||||
|
(void)order;
|
||||||
|
return c89atomic_compare_and_swap_64(ptr, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
|
#define c89atomic_store_explicit_8( dst, src, order) (void)c89atomic_exchange_explicit_8 (dst, src, order)
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_16)
|
||||||
|
#define c89atomic_store_explicit_16(dst, src, order) (void)c89atomic_exchange_explicit_16(dst, src, order)
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_32)
|
||||||
|
#define c89atomic_store_explicit_32(dst, src, order) (void)c89atomic_exchange_explicit_32(dst, src, order)
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_64)
|
||||||
|
#define c89atomic_store_explicit_64(dst, src, order) (void)c89atomic_exchange_explicit_64(dst, src, order)
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
|
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint8 oldValue;
|
volatile c89atomic_uint8 oldValue;
|
||||||
@@ -8565,6 +8642,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_16)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
|
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint16 oldValue;
|
volatile c89atomic_uint16 oldValue;
|
||||||
@@ -8576,6 +8655,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_32)
|
||||||
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_uint32 __stdcall c89atomic_fetch_sub_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint32 oldValue;
|
volatile c89atomic_uint32 oldValue;
|
||||||
@@ -8587,6 +8668,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_64)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_sub_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 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_uint64 oldValue;
|
volatile c89atomic_uint64 oldValue;
|
||||||
@@ -8598,6 +8681,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
|
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint8 oldValue;
|
volatile c89atomic_uint8 oldValue;
|
||||||
@@ -8609,6 +8694,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_16)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_and_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 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_uint16 oldValue;
|
volatile c89atomic_uint16 oldValue;
|
||||||
@@ -8620,6 +8707,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_32)
|
||||||
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_uint32 __stdcall c89atomic_fetch_and_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint32 oldValue;
|
volatile c89atomic_uint32 oldValue;
|
||||||
@@ -8631,6 +8720,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_64)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
|
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint64 oldValue;
|
volatile c89atomic_uint64 oldValue;
|
||||||
@@ -8642,6 +8733,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#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_xor_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint8 oldValue;
|
volatile c89atomic_uint8 oldValue;
|
||||||
@@ -8653,6 +8746,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#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)
|
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 oldValue;
|
||||||
@@ -8664,6 +8759,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_32)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
|
static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
|
||||||
{
|
{
|
||||||
volatile c89atomic_uint32 oldValue;
|
volatile c89atomic_uint32 oldValue;
|
||||||
@@ -8675,6 +8772,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_64)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_xor_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
|
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 oldValue;
|
volatile c89atomic_uint64 oldValue;
|
||||||
@@ -8686,6 +8785,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_or_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;
|
||||||
@@ -8697,6 +8798,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
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)
|
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 oldValue;
|
||||||
@@ -8708,6 +8811,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
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)
|
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 oldValue;
|
||||||
@@ -8719,6 +8824,8 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
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)
|
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 oldValue;
|
||||||
@@ -8730,16 +8837,42 @@ typedef unsigned char c89atomic_flag;
|
|||||||
(void)order;
|
(void)order;
|
||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_8)
|
||||||
#define c89atomic_test_and_set_explicit_8( dst, order) c89atomic_exchange_explicit_8 (dst, 1, order)
|
#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)
|
#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)
|
#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)
|
#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)
|
#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)
|
#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)
|
#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)
|
#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)
|
#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 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
|
||||||
@@ -8756,8 +8889,6 @@ typedef unsigned char c89atomic_flag;
|
|||||||
#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;
|
|||||||
#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,10 +9455,13 @@ 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)
|
||||||
|
#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_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 expectedValue;
|
||||||
@@ -9339,6 +9477,8 @@ c89atomic_bool c89atomic_compare_exchange_strong_explicit_8(volatile c89atomic_u
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_16)
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
c89atomic_uint16 expectedValue;
|
c89atomic_uint16 expectedValue;
|
||||||
@@ -9354,6 +9494,8 @@ c89atomic_bool c89atomic_compare_exchange_strong_explicit_16(volatile c89atomic_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_32)
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
c89atomic_uint32 expectedValue;
|
c89atomic_uint32 expectedValue;
|
||||||
@@ -9369,6 +9511,8 @@ c89atomic_bool c89atomic_compare_exchange_strong_explicit_32(volatile c89atomic_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(C89ATOMIC_HAS_64)
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
c89atomic_uint64 expectedValue;
|
c89atomic_uint64 expectedValue;
|
||||||
@@ -9384,6 +9528,7 @@ c89atomic_bool c89atomic_compare_exchange_strong_explicit_64(volatile c89atomic_
|
|||||||
return 0;
|
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_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_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_32(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder)
|
||||||
@@ -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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user