From 1e27b33f266e678d9d34cd4d4e29fd04bde0636c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 15 Jun 2016 22:18:24 +0200 Subject: [PATCH] Consider fired timers to be events that cause processEvents to return. --- source/eventcore/drivers/posix.d | 2 +- source/eventcore/drivers/timer.d | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/eventcore/drivers/posix.d b/source/eventcore/drivers/posix.d index 04a4e66..d74bc3f 100644 --- a/source/eventcore/drivers/posix.d +++ b/source/eventcore/drivers/posix.d @@ -84,7 +84,7 @@ abstract class PosixEventDriver : EventDriver { got_events = doProcessEvents(nextto); long prev_step = now; now = currStdTime; - processTimers(now); + got_events |= processTimers(now); if (timeout != Duration.max) timeout -= (now - prev_step).hnsecs; } while (timeout > 0.seconds && !m_exit && !got_events); diff --git a/source/eventcore/drivers/timer.d b/source/eventcore/drivers/timer.d index 9c4239d..28749b5 100644 --- a/source/eventcore/drivers/timer.d +++ b/source/eventcore/drivers/timer.d @@ -34,10 +34,10 @@ mixin template DefaultTimerImpl() { return m_timerQueue.length ? (m_timerQueue.front.timeout - stdtime).hnsecs : Duration.max; } - final protected void processTimers(long stdtime) - @trusted { + final protected bool processTimers(long stdtime) + @trusted nothrow { assert(m_firedTimers.length == 0); - if (m_timerQueue.empty) return; + if (m_timerQueue.empty) return false; TimerSlot ts = void; ts.timeout = stdtime+1; @@ -62,8 +62,12 @@ mixin template DefaultTimerImpl() { foreach (cb; tm.callbacks) cb(tm.id); + bool any_fired = m_firedTimers.length > 0; + m_firedTimers.length = 0; m_firedTimers.assumeSafeAppend(); + + return any_fired; } final override TimerID createTimer()