Make timer wait semantics consistent with other wait() functions.
This commit is contained in:
parent
270543d3d8
commit
8ecc583e4d
|
@ -55,12 +55,17 @@ final class LoopTimeoutTimerDriver : EventDriverTimers {
|
||||||
|
|
||||||
// NOTE: this isn't yet verified to work under all circumstances
|
// NOTE: this isn't yet verified to work under all circumstances
|
||||||
auto elems = m_timerQueue[0 .. fired.length];
|
auto elems = m_timerQueue[0 .. fired.length];
|
||||||
scope (failure) assert(false);
|
|
||||||
m_timerQueue.linearRemove(elems);
|
|
||||||
|
|
||||||
foreach (tm; m_firedTimers)
|
{
|
||||||
foreach (cb; tm.callbacks)
|
scope (failure) assert(false);
|
||||||
cb(tm.id);
|
m_timerQueue.linearRemove(elems);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (tm; m_firedTimers) {
|
||||||
|
auto cb = tm.callback;
|
||||||
|
tm.callback = null;
|
||||||
|
cb(tm.id);
|
||||||
|
}
|
||||||
|
|
||||||
bool any_fired = m_firedTimers.length > 0;
|
bool any_fired = m_firedTimers.length > 0;
|
||||||
|
|
||||||
|
@ -102,7 +107,6 @@ final class LoopTimeoutTimerDriver : EventDriverTimers {
|
||||||
auto tm = m_timers[timer];
|
auto tm = m_timers[timer];
|
||||||
if (!tm.pending) return;
|
if (!tm.pending) return;
|
||||||
tm.pending = false;
|
tm.pending = false;
|
||||||
tm.callbacks.length = 0;
|
|
||||||
|
|
||||||
TimerSlot cmp = void;
|
TimerSlot cmp = void;
|
||||||
cmp.timeout = tm.timeout-1;
|
cmp.timeout = tm.timeout-1;
|
||||||
|
@ -130,17 +134,15 @@ final class LoopTimeoutTimerDriver : EventDriverTimers {
|
||||||
|
|
||||||
final override void wait(TimerID timer, TimerCallback callback)
|
final override void wait(TimerID timer, TimerCallback callback)
|
||||||
{
|
{
|
||||||
m_timers[timer].callbacks ~= callback;
|
assert(!m_timers[timer].callback);
|
||||||
|
m_timers[timer].callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void cancelWait(TimerID timer, TimerCallback callback)
|
final override void cancelWait(TimerID timer)
|
||||||
{
|
{
|
||||||
import std.algorithm.mutation : remove;
|
|
||||||
import std.algorithm.searching : countUntil;
|
|
||||||
|
|
||||||
auto pt = m_timers[timer];
|
auto pt = m_timers[timer];
|
||||||
auto idx = pt.callbacks.countUntil(callback);
|
assert(pt.callback);
|
||||||
if (idx >= 0) pt.callbacks = pt.callbacks.remove(idx);
|
pt.callback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void addRef(TimerID descriptor)
|
final override void addRef(TimerID descriptor)
|
||||||
|
@ -173,5 +175,5 @@ struct TimerSlot {
|
||||||
bool pending;
|
bool pending;
|
||||||
long timeout; // stdtime
|
long timeout; // stdtime
|
||||||
long repeatDuration;
|
long repeatDuration;
|
||||||
TimerCallback[] callbacks; // TODO: use a list with small-value optimization
|
TimerCallback callback; // TODO: use a list with small-value optimization
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue