Consider fired timers to be events that cause processEvents to return.

This commit is contained in:
Sönke Ludwig 2016-06-15 22:18:24 +02:00
parent 96a8c95b81
commit 1e27b33f26
2 changed files with 8 additions and 4 deletions

View file

@ -84,7 +84,7 @@ abstract class PosixEventDriver : EventDriver {
got_events = doProcessEvents(nextto); got_events = doProcessEvents(nextto);
long prev_step = now; long prev_step = now;
now = currStdTime; now = currStdTime;
processTimers(now); got_events |= processTimers(now);
if (timeout != Duration.max) if (timeout != Duration.max)
timeout -= (now - prev_step).hnsecs; timeout -= (now - prev_step).hnsecs;
} while (timeout > 0.seconds && !m_exit && !got_events); } while (timeout > 0.seconds && !m_exit && !got_events);

View file

@ -34,10 +34,10 @@ mixin template DefaultTimerImpl() {
return m_timerQueue.length ? (m_timerQueue.front.timeout - stdtime).hnsecs : Duration.max; return m_timerQueue.length ? (m_timerQueue.front.timeout - stdtime).hnsecs : Duration.max;
} }
final protected void processTimers(long stdtime) final protected bool processTimers(long stdtime)
@trusted { @trusted nothrow {
assert(m_firedTimers.length == 0); assert(m_firedTimers.length == 0);
if (m_timerQueue.empty) return; if (m_timerQueue.empty) return false;
TimerSlot ts = void; TimerSlot ts = void;
ts.timeout = stdtime+1; ts.timeout = stdtime+1;
@ -62,8 +62,12 @@ mixin template DefaultTimerImpl() {
foreach (cb; tm.callbacks) foreach (cb; tm.callbacks)
cb(tm.id); cb(tm.id);
bool any_fired = m_firedTimers.length > 0;
m_firedTimers.length = 0; m_firedTimers.length = 0;
m_firedTimers.assumeSafeAppend(); m_firedTimers.assumeSafeAppend();
return any_fired;
} }
final override TimerID createTimer() final override TimerID createTimer()