From 85c4acea80427313b61c70b76f97bc087593122d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 26 Sep 2026 17:16:08 +1000 Subject: [PATCH] Timer: Use global initializer for timer frequency on Windows Gets rid of a branch. --- src/common/timer.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/common/timer.cpp b/src/common/timer.cpp index a729d384e..1fbf02b34 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -19,9 +19,6 @@ #ifdef _WIN32 -static double s_counter_frequency; -static bool s_counter_initialized = false; - namespace { struct SleepTimerHandle @@ -59,17 +56,14 @@ static HANDLE GetSleepTimer() return s_sleep_timer.handle; } +static const double s_counter_frequency = []() { + LARGE_INTEGER freq = {}; + QueryPerformanceFrequency(&freq); + return static_cast(freq.QuadPart) / 1000000000.0; +}(); + double Timer::GetFrequency() { - // even if this races, it should still result in the same value.. - if (!s_counter_initialized) - { - LARGE_INTEGER Freq; - QueryPerformanceFrequency(&Freq); - s_counter_frequency = static_cast(Freq.QuadPart) / 1000000000.0; - s_counter_initialized = true; - } - return s_counter_frequency; }