Fix atomics to accept constant

This commit is contained in:
Wojtek Figat
2024-04-13 13:20:43 +02:00
parent 9c2c02c1cf
commit d42e315e55
5 changed files with 12 additions and 12 deletions

View File

@@ -55,13 +55,13 @@ public:
{ {
return __sync_fetch_and_add(dst, value); return __sync_fetch_and_add(dst, value);
} }
FORCE_INLINE static int32 AtomicRead(int32 volatile* dst) FORCE_INLINE static int32 AtomicRead(int32 const volatile* dst)
{ {
int32 result; int32 result;
__atomic_load(dst, &result, __ATOMIC_RELAXED); __atomic_load(dst, &result, __ATOMIC_RELAXED);
return result; return result;
} }
FORCE_INLINE static int64 AtomicRead(int64 volatile* dst) FORCE_INLINE static int64 AtomicRead(int64 const volatile* dst)
{ {
int64 result; int64 result;
__atomic_load(dst, &result, __ATOMIC_RELAXED); __atomic_load(dst, &result, __ATOMIC_RELAXED);

View File

@@ -45,21 +45,21 @@ public:
{ {
return __sync_fetch_and_add(dst, value); return __sync_fetch_and_add(dst, value);
} }
FORCE_INLINE static int32 AtomicRead(int32 volatile* dst) FORCE_INLINE static int32 AtomicRead(int32 const volatile* dst)
{ {
return __atomic_load_n(dst, __ATOMIC_RELAXED); return __atomic_load_n(dst, __ATOMIC_RELAXED);
} }
FORCE_INLINE static int64 AtomicRead(int64 volatile* dst) FORCE_INLINE static int64 AtomicRead(int64 const volatile* dst)
{ {
return __atomic_load_n(dst, __ATOMIC_RELAXED); return __atomic_load_n(dst, __ATOMIC_RELAXED);
} }
FORCE_INLINE static void AtomicStore(int32 volatile* dst, int32 value) FORCE_INLINE static void AtomicStore(int32 volatile* dst, int32 value)
{ {
__atomic_store(dst, &value, __ATOMIC_SEQ_CST); __atomic_store_n((volatile int32*)dst, value, __ATOMIC_RELAXED);
} }
FORCE_INLINE static void AtomicStore(int64 volatile* dst, int64 value) FORCE_INLINE static void AtomicStore(int64 volatile* dst, int64 value)
{ {
__atomic_store(dst, &value, __ATOMIC_SEQ_CST); __atomic_store_n((volatile int64*)dst, value, __ATOMIC_RELAXED);
} }
FORCE_INLINE static void Prefetch(void const* ptr) FORCE_INLINE static void Prefetch(void const* ptr)
{ {

View File

@@ -270,14 +270,14 @@ public:
/// </summary> /// </summary>
/// <param name="dst">A pointer to the destination value.</param> /// <param name="dst">A pointer to the destination value.</param>
/// <returns>The function returns the value of the destination parameter.</returns> /// <returns>The function returns the value of the destination parameter.</returns>
static int32 AtomicRead(int32 volatile* dst) = delete; static int32 AtomicRead(int32 const volatile* dst) = delete;
/// <summary> /// <summary>
/// Performs an atomic 64-bit variable read operation on the specified values. /// Performs an atomic 64-bit variable read operation on the specified values.
/// </summary> /// </summary>
/// <param name="dst">A pointer to the destination value.</param> /// <param name="dst">A pointer to the destination value.</param>
/// <returns>The function returns the value of the destination parameter.</returns> /// <returns>The function returns the value of the destination parameter.</returns>
static int64 AtomicRead(int64 volatile* dst) = delete; static int64 AtomicRead(int64 const volatile* dst) = delete;
/// <summary> /// <summary>
/// Sets a 32-bit variable to the specified value as an atomic operation. /// Sets a 32-bit variable to the specified value as an atomic operation.

View File

@@ -69,13 +69,13 @@ public:
{ {
return __sync_fetch_and_add(dst, value); return __sync_fetch_and_add(dst, value);
} }
FORCE_INLINE static int32 AtomicRead(int32 volatile* dst) FORCE_INLINE static int32 AtomicRead(int32 const volatile* dst)
{ {
int32 result; int32 result;
__atomic_load(dst, &result, __ATOMIC_SEQ_CST); __atomic_load(dst, &result, __ATOMIC_SEQ_CST);
return result; return result;
} }
FORCE_INLINE static int64 AtomicRead(int64 volatile* dst) FORCE_INLINE static int64 AtomicRead(int64 const volatile* dst)
{ {
int64 result; int64 result;
__atomic_load(dst, &result, __ATOMIC_SEQ_CST); __atomic_load(dst, &result, __ATOMIC_SEQ_CST);

View File

@@ -63,11 +63,11 @@ public:
return _interlockedexchangeadd64(dst, value); return _interlockedexchangeadd64(dst, value);
#endif #endif
} }
static int32 AtomicRead(int32 volatile* dst) static int32 AtomicRead(int32 const volatile* dst)
{ {
return (int32)_InterlockedCompareExchange((long volatile*)dst, 0, 0); return (int32)_InterlockedCompareExchange((long volatile*)dst, 0, 0);
} }
static int64 AtomicRead(int64 volatile* dst) static int64 AtomicRead(int64 const volatile* dst)
{ {
return _InterlockedCompareExchange64(dst, 0, 0); return _InterlockedCompareExchange64(dst, 0, 0);
} }