event/TimerEvent: assign `due` in Schedule()
This commit is contained in:
parent
2a30acd99c
commit
271b287356
|
@ -152,11 +152,10 @@ EventLoop::AbandonFD(SocketEvent &event) noexcept
|
|||
}
|
||||
|
||||
void
|
||||
EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept
|
||||
EventLoop::Insert(TimerEvent &t) noexcept
|
||||
{
|
||||
assert(IsInside());
|
||||
|
||||
t.due = SteadyNow() + d;
|
||||
timers.insert(t);
|
||||
again = true;
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ public:
|
|||
*/
|
||||
bool AbandonFD(SocketEvent &event) noexcept;
|
||||
|
||||
void AddTimer(TimerEvent &t, Event::Duration d) noexcept;
|
||||
void Insert(TimerEvent &t) noexcept;
|
||||
|
||||
/**
|
||||
* Schedule a call to DeferEvent::RunDeferred().
|
||||
|
|
|
@ -25,12 +25,22 @@ TimerEvent::Schedule(Event::Duration d) noexcept
|
|||
{
|
||||
Cancel();
|
||||
|
||||
loop.AddTimer(*this, d);
|
||||
due = loop.SteadyNow() + d;
|
||||
loop.Insert(*this);
|
||||
}
|
||||
|
||||
void
|
||||
TimerEvent::ScheduleEarlier(Event::Duration d) noexcept
|
||||
{
|
||||
if (!IsPending() || loop.SteadyNow() + d < due)
|
||||
Schedule(d);
|
||||
const auto new_due = loop.SteadyNow() + d;
|
||||
|
||||
if (IsPending()) {
|
||||
if (new_due >= due)
|
||||
return;
|
||||
|
||||
Cancel();
|
||||
}
|
||||
|
||||
due = new_due;
|
||||
loop.Insert(*this);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue