[*] Updated atomics

This commit is contained in:
Reece Wilson 2023-09-02 01:53:44 +01:00
parent 471d04a9c8
commit 01d9b6754f

View File

@ -11,6 +11,41 @@
#include <stdatomic.h> #include <stdatomic.h>
#endif #endif
#if defined(AURORA_COMPILER_MSVC)
using AuAInt8 = volatile AuInt8;
using AuAUInt8 = volatile AuUInt8;
using AuAInt16 = volatile AuInt16;
using AuAUInt16 = volatile AuUInt16;
using AuAInt32 = volatile AuInt32;
using AuAUInt32 = volatile AuUInt32;
#if defined(AURORA_IS_64BIT)
using AuAInt64 = volatile AuInt64;
using AuAUInt64 = volatile AuUInt64;
#endif
#else
using AuAInt8 = _Atomic(int8_t);
using AuAUInt8 = _Atomic(uint8_t);
using AuAInt16 = _Atomic(int16_t);
using AuAUInt16 = _Atomic(uint16_t);
using AuAInt32 = _Atomic(int32_t);
using AuAUInt32 = _Atomic(uint32_t);
#if defined(AURORA_IS_64BIT)
using AuAInt64 = _Atomic(int64_t);
using AuAUInt64 = _Atomic(uint64_t);
#endif
#endif
// Defines: // Defines:
// AuAtomicCompareExchange (no weak variants yet) // AuAtomicCompareExchange (no weak variants yet)
// - // -
@ -380,8 +415,9 @@ template <class T>
inline auline T AuAtomicUtils<T>::Load(T *in) inline auline T AuAtomicUtils<T>::Load(T *in)
{ {
#if defined(AURORA_COMPILER_MSVC) && (defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)) #if defined(AURORA_COMPILER_MSVC) && (defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86))
::_ReadWriteBarrier(); // compile-time only! we use this to prevent optimizations. x86/64 does not care so long as we're aligned. const auto read = *in;
return *in; ::_ReadWriteBarrier();
return read;
#elif defined(AURORA_COMPILER_MSVC) #elif defined(AURORA_COMPILER_MSVC)
::MemoryBarrier(); // works on all legacy MSVC targets including AMD64, IA64, and POWER ::MemoryBarrier(); // works on all legacy MSVC targets including AMD64, IA64, and POWER
return *in; return *in;
@ -528,8 +564,7 @@ inline auline
void AuAtomicUtils<AuUInt8>::ClearU8Lock(AuUInt8 *in) void AuAtomicUtils<AuUInt8>::ClearU8Lock(AuUInt8 *in)
{ {
#if defined(AURORA_COMPILER_MSVC) && (defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)) #if defined(AURORA_COMPILER_MSVC) && (defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86))
*in = 0; ::_InterlockedExchange8((volatile char *)in, 0);
::_ReadWriteBarrier();
#elif defined(AURORA_COMPILER_MSVC) #elif defined(AURORA_COMPILER_MSVC)
// i think this will work on aarch64 and most risc architectures // i think this will work on aarch64 and most risc architectures
InterlockedAndRelease((volatile LONG *)in, ~0xFF); InterlockedAndRelease((volatile LONG *)in, ~0xFF);