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
|
void
|
||||||
EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept
|
EventLoop::Insert(TimerEvent &t) noexcept
|
||||||
{
|
{
|
||||||
assert(IsInside());
|
assert(IsInside());
|
||||||
|
|
||||||
t.due = SteadyNow() + d;
|
|
||||||
timers.insert(t);
|
timers.insert(t);
|
||||||
again = true;
|
again = true;
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool AbandonFD(SocketEvent &event) noexcept;
|
bool AbandonFD(SocketEvent &event) noexcept;
|
||||||
|
|
||||||
void AddTimer(TimerEvent &t, Event::Duration d) noexcept;
|
void Insert(TimerEvent &t) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule a call to DeferEvent::RunDeferred().
|
* Schedule a call to DeferEvent::RunDeferred().
|
||||||
|
@ -25,12 +25,22 @@ TimerEvent::Schedule(Event::Duration d) noexcept
|
|||||||
{
|
{
|
||||||
Cancel();
|
Cancel();
|
||||||
|
|
||||||
loop.AddTimer(*this, d);
|
due = loop.SteadyNow() + d;
|
||||||
|
loop.Insert(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TimerEvent::ScheduleEarlier(Event::Duration d) noexcept
|
TimerEvent::ScheduleEarlier(Event::Duration d) noexcept
|
||||||
{
|
{
|
||||||
if (!IsPending() || loop.SteadyNow() + d < due)
|
const auto new_due = loop.SteadyNow() + d;
|
||||||
Schedule(d);
|
|
||||||
|
if (IsPending()) {
|
||||||
|
if (new_due >= due)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
due = new_due;
|
||||||
|
loop.Insert(*this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user