diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index ee278e2906..93fe538758 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2025 Wildfire Games. +/* Copyright (c) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -224,19 +224,6 @@ switch(x % 2) # define SENTINEL_ARG #endif -/** - * prevent the compiler from reordering loads or stores across this point. - **/ -#if MSC_VERSION -# include -# pragma intrinsic(_ReadWriteBarrier) -# define COMPILER_FENCE _ReadWriteBarrier() -#elif GCC_VERSION -# define COMPILER_FENCE asm volatile("" : : : "memory") -#else -# define COMPILER_FENCE -#endif - // try to define _W64, if not already done // (this is useful for catching pointer size bugs) diff --git a/source/lib/file/io/io.h b/source/lib/file/io/io.h index 903be5b7d3..46f5a4e9ed 100644 --- a/source/lib/file/io/io.h +++ b/source/lib/file/io/io.h @@ -263,7 +263,7 @@ static inline Status Run(const Operation& op, const Parameters& p = Parameters() #if ENABLE_IO_STATS const double t0 = timer_Time(); - COMPILER_FENCE; + std::atomic_signal_fence(std::memory_order::seq_cst); #endif size_t numBlocks = p.blockSize? DivideRoundUp(static_cast(op.m_Size), p.blockSize) : 1; @@ -290,7 +290,7 @@ static inline Status Run(const Operation& op, const Parameters& p = Parameters() } #if ENABLE_IO_STATS - COMPILER_FENCE; + std::atomic_signal_fence(std::memory_order::seq_cst); const double t1 = timer_Time(); const off_t totalSize = p.blockSize? numBlocks*p.blockSize : op.m_Size; debug_printf("IO: %.2f MB/s (%.2f)\n", totalSize/(t1-t0)/1e6, (t1-t0)*1e3); diff --git a/source/lib/sysdep/os/win/wposix/waio.cpp b/source/lib/sysdep/os/win/wposix/waio.cpp index 5685b05c9e..b410866728 100644 --- a/source/lib/sysdep/os/win/wposix/waio.cpp +++ b/source/lib/sysdep/os/win/wposix/waio.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -657,7 +657,7 @@ ssize_t aio_return(struct aiocb* cb) const ULONG_PTR bytesTransferred = ovl->InternalHigh; cb->ovl = 0; // prevent further calls to aio_error/aio_return - COMPILER_FENCE; + std::atomic_signal_fence(std::memory_order::seq_cst); fcb->ovl.Deallocate(ovl); return (status == ERROR_SUCCESS)? bytesTransferred : -1; diff --git a/source/lib/sysdep/os/win/wvm.cpp b/source/lib/sysdep/os/win/wvm.cpp index 24b983fef1..88432d9d98 100644 --- a/source/lib/sysdep/os/win/wvm.cpp +++ b/source/lib/sysdep/os/win/wvm.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -153,9 +153,11 @@ static void* AllocateLargeOrSmallPages(uintptr_t address, size_t size, DWORD all // note: this call can take SECONDS, which is why several checks are // undertaken before we even try. these aren't authoritative, so we // at least prevent future attempts if it takes too long. - const double startTime = timer_Time(); COMPILER_FENCE; + const double startTime = timer_Time(); + std::atomic_signal_fence(std::memory_order::seq_cst); void* largePages = VirtualAllocExNuma(hProcess, LPVOID(alignedAddress), alignedSize, allocationType|MEM_LARGE_PAGES, protect, node); - const double elapsedTime = timer_Time() - startTime; COMPILER_FENCE; + const double elapsedTime = timer_Time() - startTime; + std::atomic_signal_fence(std::memory_order::seq_cst); if(elapsedTime > 0.5) largePageAllocationTookTooLong = true; // avoid large pages next time if(largePages)