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.
This commit is contained in:
Hiroki Noda 2018-12-23 21:37:12 +09:00
parent 19a8fc64c8
commit 3b6b2ab900

View file

@ -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));
}