From 68517763584d2dbe2ce8a05f927659ea93d2094e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 30 Jan 2017 19:54:38 +0100 Subject: [PATCH] Add EventDriverTimers.isUnique. --- source/eventcore/driver.d | 3 +++ source/eventcore/drivers/timer.d | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index a0d9843..ac662ea 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -422,6 +422,9 @@ interface EventDriverTimers { Returns `false` $(I iff) the last reference was removed by this call. */ bool releaseRef(TimerID descriptor); + + /// Determines if the given timer's reference count equals one. + bool isUnique(TimerID descriptor) const; } interface EventDriverWatchers { diff --git a/source/eventcore/drivers/timer.d b/source/eventcore/drivers/timer.d index 80e3ad9..d97d09c 100644 --- a/source/eventcore/drivers/timer.d +++ b/source/eventcore/drivers/timer.d @@ -88,6 +88,7 @@ final class LoopTimeoutTimerDriver : EventDriverTimers { assert(tm !is null); tm.id = id; tm.refCount = 1; + tm.timeout = long.max; m_timers[id] = tm; return id; } @@ -138,6 +139,7 @@ final class LoopTimeoutTimerDriver : EventDriverTimers { final override void wait(TimerID timer, TimerCallback callback) { + import eventcore.internal.utils; print("emit timer"); assert(!m_timers[timer].callback, "Calling wait() no a timer that is already waiting."); m_timers[timer].callback = callback; } @@ -179,6 +181,12 @@ final class LoopTimeoutTimerDriver : EventDriverTimers { return true; } + + final bool isUnique(TimerID descriptor) + const { + if (descriptor == TimerID.init) return false; + return m_timers[descriptor].refCount == 1; + } } struct TimerSlot {