From 45c9865b69dd6343e6463842a54a41263f17b866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 17 Jun 2016 16:49:13 +0200 Subject: [PATCH] Fix timer ID allocation. --- source/eventcore/drivers/timer.d | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/eventcore/drivers/timer.d b/source/eventcore/drivers/timer.d index 28749b5..f800dfb 100644 --- a/source/eventcore/drivers/timer.d +++ b/source/eventcore/drivers/timer.d @@ -72,7 +72,7 @@ mixin template DefaultTimerImpl() { final override TimerID createTimer() @trusted { - auto id = cast(TimerID)(m_lastTimerID + 1); + auto id = cast(TimerID)(++m_lastTimerID); TimerSlot* tm; try tm = ms_allocator.make!TimerSlot; catch (Exception e) return TimerID.invalid; @@ -145,11 +145,19 @@ mixin template DefaultTimerImpl() { final override void addRef(TimerID descriptor) { + assert(descriptor != TimerID.init, "Invalid timer ID."); + assert(descriptor in m_timers, "Unknown timer ID."); + if (descriptor !in m_timers) return; + m_timers[descriptor].refCount++; } final override void releaseRef(TimerID descriptor) { + assert(descriptor != TimerID.init, "Invalid timer ID."); + assert(descriptor in m_timers, "Unknown timer ID."); + if (descriptor !in m_timers) return; + auto tm = m_timers[descriptor]; if (!--tm.refCount) { if (tm.pending) stopTimer(tm.id);