Fix timer ID allocation.

This commit is contained in:
Sönke Ludwig 2016-06-17 16:49:13 +02:00
parent 32394bb4c9
commit 45c9865b69

View file

@ -72,7 +72,7 @@ mixin template DefaultTimerImpl() {
final override TimerID createTimer() final override TimerID createTimer()
@trusted { @trusted {
auto id = cast(TimerID)(m_lastTimerID + 1); auto id = cast(TimerID)(++m_lastTimerID);
TimerSlot* tm; TimerSlot* tm;
try tm = ms_allocator.make!TimerSlot; try tm = ms_allocator.make!TimerSlot;
catch (Exception e) return TimerID.invalid; catch (Exception e) return TimerID.invalid;
@ -145,11 +145,19 @@ mixin template DefaultTimerImpl() {
final override void addRef(TimerID descriptor) 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++; m_timers[descriptor].refCount++;
} }
final override void releaseRef(TimerID descriptor) 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]; auto tm = m_timers[descriptor];
if (!--tm.refCount) { if (!--tm.refCount) {
if (tm.pending) stopTimer(tm.id); if (tm.pending) stopTimer(tm.id);