From 8614c4436b599f32d33466f20320615ba982ccbb Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Thu, 7 Nov 2019 15:19:32 +0100 Subject: [PATCH] [core] Minor CTimer::sleepto improvement. Replaced two if statements with a single one. --- srtcore/common.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/srtcore/common.cpp b/srtcore/common.cpp index b8e89e8e8..5614de4af 100644 --- a/srtcore/common.cpp +++ b/srtcore/common.cpp @@ -207,9 +207,9 @@ void CTimer::sleepto(uint64_t nexttime_tk) #if USE_BUSY_WAITING #if defined(_WIN32) - const uint64_t threshold = 10000; // 10 ms on Windows: bad accuracy of timers + const uint64_t threshold_us = 10000; // 10 ms on Windows: bad accuracy of timers #else - const uint64_t threshold = 1000; // 1 ms on non-Windows platforms + const uint64_t threshold_us = 1000; // 1 ms on non-Windows platforms #endif #endif @@ -217,12 +217,11 @@ void CTimer::sleepto(uint64_t nexttime_tk) { #if USE_BUSY_WAITING uint64_t wait_us = (m_ullSchedTime_tk - t) / s_ullCPUFrequency; - if (wait_us > threshold) - wait_us -= threshold; - if (wait_us < threshold) + if (wait_us <= 2 * threshold_us) break; + wait_us -= threshold_us; #else - const uint64_t wait_us = (m_ullSchedTime_tk - t) / getCPUFrequency(); + const uint64_t wait_us = (m_ullSchedTime_tk - t) / s_ullCPUFrequency; if (wait_us == 0) break; #endif