Merge pull request #96 from kubo39/use-monotonic-clocktype
Use monotonic clock for timeout
This commit is contained in:
commit
91db8899c5
|
@ -404,17 +404,16 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat
|
||||||
|
|
||||||
private void run()
|
private void run()
|
||||||
nothrow @trusted {
|
nothrow @trusted {
|
||||||
import core.time : msecs;
|
import core.time : MonoTime, msecs;
|
||||||
import std.algorithm.comparison : min;
|
import std.algorithm.comparison : min;
|
||||||
import std.datetime : Clock, UTC;
|
|
||||||
|
|
||||||
try while (true) {
|
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) {
|
while (true) {
|
||||||
try synchronized (m_changesMutex) {
|
try synchronized (m_changesMutex) {
|
||||||
if (m_changesEvent == EventID.invalid) return;
|
if (m_changesEvent == EventID.invalid) return;
|
||||||
} catch (Exception e) assert(false, "Mutex lock failed: "~e.msg);
|
} 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;
|
if (remaining <= 0.msecs) break;
|
||||||
sleep(min(1000.msecs, remaining));
|
sleep(min(1000.msecs, remaining));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ module test;
|
||||||
import eventcore.core;
|
import eventcore.core;
|
||||||
import eventcore.internal.utils : print;
|
import eventcore.internal.utils : print;
|
||||||
import core.thread : Thread;
|
import core.thread : Thread;
|
||||||
import core.time : Duration, msecs;
|
import core.time : Duration, MonoTime, msecs;
|
||||||
import std.file : exists, remove, rename, rmdirRecurse, mkdir;
|
import std.file : exists, remove, rename, rmdirRecurse, mkdir;
|
||||||
import std.format : format;
|
import std.format : format;
|
||||||
import std.functional : toDelegate;
|
import std.functional : toDelegate;
|
||||||
|
@ -80,9 +80,7 @@ void testCallback(WatcherID w, in ref FileChange ch)
|
||||||
|
|
||||||
void expectChange(FileChange ch, bool expect_change)
|
void expectChange(FileChange ch, bool expect_change)
|
||||||
{
|
{
|
||||||
import std.datetime : Clock, UTC;
|
auto starttime = MonoTime.currTime();
|
||||||
|
|
||||||
auto starttime = Clock.currTime(UTC());
|
|
||||||
again: while (!pendingChanges.length) {
|
again: while (!pendingChanges.length) {
|
||||||
auto er = eventDriver.core.processEvents(10.msecs);
|
auto er = eventDriver.core.processEvents(10.msecs);
|
||||||
switch (er) {
|
switch (er) {
|
||||||
|
@ -95,7 +93,7 @@ void expectChange(FileChange ch, bool expect_change)
|
||||||
assert(!expect_change, "No watcher left, but expected change.");
|
assert(!expect_change, "No watcher left, but expected change.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pendingChanges.length && Clock.currTime(UTC()) - starttime >= 2000.msecs) {
|
if (!pendingChanges.length && MonoTime.currTime() - starttime >= 2000.msecs) {
|
||||||
assert(!expect_change, format("Got no change, expected %s.", ch));
|
assert(!expect_change, format("Got no change, expected %s.", ch));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,16 @@
|
||||||
module test;
|
module test;
|
||||||
|
|
||||||
import eventcore.core;
|
import eventcore.core;
|
||||||
import std.datetime : Clock, SysTime, UTC;
|
import core.time : Duration, MonoTime, msecs;
|
||||||
import std.stdio : writefln;
|
import std.stdio : writefln;
|
||||||
import core.time : Duration, msecs;
|
|
||||||
|
|
||||||
SysTime s_startTime;
|
MonoTime s_startTime;
|
||||||
int s_cnt = 0;
|
int s_cnt = 0;
|
||||||
bool s_done;
|
bool s_done;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
s_startTime = Clock.currTime(UTC());
|
s_startTime = MonoTime.currTime();
|
||||||
|
|
||||||
auto tm = eventDriver.timers.create();
|
auto tm = eventDriver.timers.create();
|
||||||
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
||||||
|
@ -23,7 +22,7 @@ void main()
|
||||||
|
|
||||||
{
|
{
|
||||||
scope (failure) assert(false);
|
scope (failure) assert(false);
|
||||||
dur = Clock.currTime(UTC()) - s_startTime;
|
dur = MonoTime.currTime() - s_startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -37,7 +36,7 @@ void main()
|
||||||
|
|
||||||
void secondTier(TimerID timer) nothrow @safe {
|
void secondTier(TimerID timer) nothrow @safe {
|
||||||
try {
|
try {
|
||||||
auto dur = Clock.currTime(UTC()) - s_startTime;
|
auto dur = MonoTime.currTime() - s_startTime;
|
||||||
s_cnt++;
|
s_cnt++;
|
||||||
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
||||||
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
||||||
|
|
|
@ -5,17 +5,16 @@
|
||||||
module test;
|
module test;
|
||||||
|
|
||||||
import eventcore.core;
|
import eventcore.core;
|
||||||
import std.datetime : Clock, SysTime, UTC;
|
import core.time : Duration, MonoTime, msecs;
|
||||||
import std.stdio : writefln;
|
import std.stdio : writefln;
|
||||||
import core.time : Duration, msecs;
|
|
||||||
|
|
||||||
SysTime s_startTime;
|
MonoTime s_startTime;
|
||||||
int s_cnt = 0;
|
int s_cnt = 0;
|
||||||
bool s_done;
|
bool s_done;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
s_startTime = Clock.currTime(UTC());
|
s_startTime = MonoTime.currTime();
|
||||||
|
|
||||||
bool timer1fired = false;
|
bool timer1fired = false;
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ void main()
|
||||||
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
||||||
try {
|
try {
|
||||||
writefln("First timer");
|
writefln("First timer");
|
||||||
auto dur = Clock.currTime(UTC()) - s_startTime;
|
auto dur = MonoTime.currTime() - s_startTime;
|
||||||
|
|
||||||
assert(dur >= 1200.msecs, (dur - 1200.msecs).toString());
|
assert(dur >= 1200.msecs, (dur - 1200.msecs).toString());
|
||||||
assert(dur < 1300.msecs, (dur - 1200.msecs).toString());
|
assert(dur < 1300.msecs, (dur - 1200.msecs).toString());
|
||||||
|
@ -43,7 +42,7 @@ void main()
|
||||||
try {
|
try {
|
||||||
writefln("Second timer");
|
writefln("Second timer");
|
||||||
|
|
||||||
auto dur = Clock.currTime(UTC()) - s_startTime;
|
auto dur = MonoTime.currTime() - s_startTime;
|
||||||
s_cnt++;
|
s_cnt++;
|
||||||
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
||||||
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
||||||
|
|
Loading…
Reference in a new issue