roll back previous commit (use standard C++ atomics on msvc

This commit is contained in:
daan 2020-09-05 11:29:38 -07:00
parent 102a85937e
commit 83bd352f37

View File

@ -17,7 +17,7 @@ terms of the MIT license. A copy of the license can be found in the file
// instead of passing the memory order as a parameter. // instead of passing the memory order as a parameter.
// ----------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------
#if defined(__cplusplus) && !defined(_MSC_VER) #if defined(__cplusplus)
// Use C++ atomics // Use C++ atomics
#include <atomic> #include <atomic>
#define _Atomic(tp) std::atomic<tp> #define _Atomic(tp) std::atomic<tp>
@ -71,7 +71,7 @@ static inline intptr_t mi_atomic_addi(_Atomic(intptr_t)* p, intptr_t add);
static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)* p, intptr_t sub); static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)* p, intptr_t sub);
#if (!defined(_MSC_VER)) // defined(__cplusplus) || !defined(_MSC_VER) #if defined(__cplusplus) || !defined(_MSC_VER)
// In C++/C11 atomics we have polymorphic atomics so can use the typed `ptr` variants (where `tp` is the type of atomic value) // In C++/C11 atomics we have polymorphic atomics so can use the typed `ptr` variants (where `tp` is the type of atomic value)
// We use these macros so we can provide a typed wrapper in MSVC in C compilation mode as well // We use these macros so we can provide a typed wrapper in MSVC in C compilation mode as well
@ -193,7 +193,7 @@ static inline void mi_atomic_store_explicit(_Atomic(uintptr_t)* p, uintptr_t x,
// These are used by the statistics // These are used by the statistics
static inline int64_t mi_atomic_addi64_relaxed(volatile _Atomic(int64_t)* p, int64_t add) { static inline int64_t mi_atomic_addi64_relaxed(volatile _Atomic(int64_t)* p, int64_t add) {
#ifdef _WIN64 #ifdef _WIN64
return (int64_t)mi_atomic_addi((_Atomic(intptr_t)*)p,add); return (int64_t)mi_atomic_addi((int64_t*)p,add);
#else #else
int64_t current; int64_t current;
int64_t sum; int64_t sum;
@ -208,7 +208,7 @@ static inline void mi_atomic_maxi64_relaxed(volatile _Atomic(int64_t)*p, int64_t
int64_t current; int64_t current;
do { do {
current = *p; current = *p;
} while (current < x && _InterlockedCompareExchange64((int64_t*)p, x, current) != current); } while (current < x && _InterlockedCompareExchange64(p, x, current) != current);
} }
// The pointer macros cast to `uintptr_t`. // The pointer macros cast to `uintptr_t`.
@ -222,8 +222,6 @@ static inline void mi_atomic_maxi64_relaxed(volatile _Atomic(int64_t)*p, int64_t
#define mi_atomic_exchange_ptr_release(tp,p,x) (tp*)mi_atomic_exchange_release((_Atomic(uintptr_t)*)(p),(uintptr_t)x) #define mi_atomic_exchange_ptr_release(tp,p,x) (tp*)mi_atomic_exchange_release((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
#define mi_atomic_exchange_ptr_acq_rel(tp,p,x) (tp*)mi_atomic_exchange_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t)x) #define mi_atomic_exchange_ptr_acq_rel(tp,p,x) (tp*)mi_atomic_exchange_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
#else
#pragma message("define atomics for this platform (not C11, C++, msvc)")
#endif #endif