Skip to content

Commit

Permalink
[core] Minor CTimer::sleepto improvement.
Browse files Browse the repository at this point in the history
Replaced two if statements with a single one.
  • Loading branch information
maxsharabayko authored and rndi committed Nov 7, 2019
1 parent 04dde1e commit 8614c44
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions srtcore/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,21 @@ 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

while (t < m_ullSchedTime_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
Expand Down

0 comments on commit 8614c44

Please sign in to comment.