Index: lib/builtins/emutls.c =================================================================== --- lib/builtins/emutls.c +++ lib/builtins/emutls.c @@ -102,7 +102,6 @@ #include #include #include -#include static LPCRITICAL_SECTION emutls_mutex; static DWORD emutls_tls_index = TLS_OUT_OF_INDEXES; @@ -207,24 +206,29 @@ /* Provide atomic load/store functions for emutls_get_index if built with MSVC. */ #if !defined(__ATOMIC_RELEASE) +#include enum { __ATOMIC_ACQUIRE = 2, __ATOMIC_RELEASE = 3 }; static __inline uintptr_t __atomic_load_n(void *ptr, unsigned type) { assert(type == __ATOMIC_ACQUIRE); #ifdef _WIN64 - return (uintptr_t) _load_be_u64(ptr); +#ifdef _M_X64 + return _InterlockedOr64_np(ptr, 0); #else - return (uintptr_t) _load_be_u32(ptr); + return _InterlockedAdd64(ptr, 0); +#endif +#else + return _InterlockedAdd(ptr, 0); #endif } static __inline void __atomic_store_n(void *ptr, uintptr_t val, unsigned type) { assert(type == __ATOMIC_RELEASE); #ifdef _WIN64 - _store_be_u64(ptr, val); + _InterlockedExchangePointer((void*volatile*)ptr, (void*) val); #else - _store_be_u32(ptr, val); + _InterlockedExchange(ptr, val); #endif }