From e94ac63a5e62a7b558ddd0513423e367db6d3369 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sun, 31 May 2026 02:32:21 +0200 Subject: [PATCH] [common/thread] fix MSVC build error with _rdstc (#4029) fixes issue reported by @bruno Signed-off-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4029 Reviewed-by: MaranBr Reviewed-by: crueter --- src/common/thread.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 49f6f5cf98..c947c88373 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -184,7 +184,11 @@ bool Event::WaitFor(const std::chrono::nanoseconds time) { _mm_monitorx(reinterpret_cast(std::addressof(is_set)), 0, 0); if (!is_set.load()) { // RDTSC may be fenced here due to atomic load +#ifdef _MSC_VER + auto const now = __rdtsc(); +#else auto const now = _rdtsc(); +#endif if (end > now) { u32 const cycles = std::min((std::numeric_limits::max)(), s64(end) - s64(now)); // See here: https://github.com/torvalds/linux/blob/948a64995aca6820abefd17f1a4258f5835c5ad9/arch/x86/lib/delay.c#L93 @@ -213,8 +217,13 @@ bool Event::WaitFor(const std::chrono::nanoseconds time) { return true; } } else { +#ifdef _MSC_VER + while (!is_set.load() && end > __rdtsc()) + Common::Windows::SleepForOneTick(); +#else while (!is_set.load() && end > _rdtsc()) Common::Windows::SleepForOneTick(); +#endif if (is_set.load()) Reset(); return true;