From 3d63d80163d7b1eb70868eb890108f4cacfbb76c Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Tue, 7 May 2024 18:01:52 -0700 Subject: [PATCH] Always use CLOCK_MONOTONIC if it's available on Unix --- src/arch/ArchHooks/ArchHooks_Unix.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/arch/ArchHooks/ArchHooks_Unix.cpp b/src/arch/ArchHooks/ArchHooks_Unix.cpp index 34e4f9fc15..a580c1ae4a 100644 --- a/src/arch/ArchHooks/ArchHooks_Unix.cpp +++ b/src/arch/ArchHooks/ArchHooks_Unix.cpp @@ -125,21 +125,18 @@ static void TestTLS() namespace { clockid_t g_Clock = CLOCK_REALTIME; - void OpenGetTime() { static bool bInitialized = false; + if( bInitialized ) return; bInitialized = true; - /* Check whether the clock is actually supported. */ + /* Check whether CLOCK_MONOTONIC is supported. + * If it isn't available, use CLOCK_REALTIME.*/ timespec ts; - if( clock_getres(CLOCK_MONOTONIC, &ts) == -1 ) - return; - - /* If the resolution is worse than a millisecond, fall back on CLOCK_REALTIME. */ - if( ts.tv_sec > 0 || ts.tv_nsec > 1000000 ) + if( clock_gettime(CLOCK_MONOTONIC, &ts) == -1 ) return; g_Clock = CLOCK_MONOTONIC;