From 3b6b2ab9006001332d222792bacf570cd35b1cc9 Mon Sep 17 00:00:00 2001 From: Hiroki Noda Date: Sun, 23 Dec 2018 21:37:12 +0900 Subject: [PATCH] Use monotonic clock for timeout The system clock can be updated manually by the sys-admin or automatically by NTP, so use monotonic clock instead. --- source/eventcore/drivers/posix/watchers.d | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/eventcore/drivers/posix/watchers.d b/source/eventcore/drivers/posix/watchers.d index c747299..67d310a 100644 --- a/source/eventcore/drivers/posix/watchers.d +++ b/source/eventcore/drivers/posix/watchers.d @@ -404,17 +404,16 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat private void run() nothrow @trusted { - import core.time : msecs; + import core.time : MonoTime, msecs; import std.algorithm.comparison : min; - import std.datetime : Clock, UTC; try while (true) { - auto timeout = Clock.currTime(UTC()) + min(m_entryCount, 60000).msecs + 1000.msecs; + auto timeout = MonoTime.currTime() + min(m_entryCount, 60000).msecs + 1000.msecs; while (true) { try synchronized (m_changesMutex) { if (m_changesEvent == EventID.invalid) return; } catch (Exception e) assert(false, "Mutex lock failed: "~e.msg); - auto remaining = timeout - Clock.currTime(UTC()); + auto remaining = timeout - MonoTime.currTime(); if (remaining <= 0.msecs) break; sleep(min(1000.msecs, remaining)); }