Commit 33ba190b authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

event/TimerEvent: add ScheduleEarlier()

parent 3783350d
...@@ -27,3 +27,10 @@ TimerEvent::Schedule(Event::Duration d) noexcept ...@@ -27,3 +27,10 @@ TimerEvent::Schedule(Event::Duration d) noexcept
loop.AddTimer(*this, d); loop.AddTimer(*this, d);
} }
void
TimerEvent::ScheduleEarlier(Event::Duration d) noexcept
{
if (!IsPending() || loop.SteadyNow() + d < due)
Schedule(d);
}
...@@ -53,8 +53,7 @@ class TimerEvent final ...@@ -53,8 +53,7 @@ class TimerEvent final
public: public:
TimerEvent(EventLoop &_loop, Callback _callback) noexcept TimerEvent(EventLoop &_loop, Callback _callback) noexcept
:loop(_loop), callback(_callback) { :loop(_loop), callback(_callback) {}
}
auto &GetEventLoop() const noexcept { auto &GetEventLoop() const noexcept {
return loop; return loop;
...@@ -66,6 +65,12 @@ public: ...@@ -66,6 +65,12 @@ public:
void Schedule(Event::Duration d) noexcept; void Schedule(Event::Duration d) noexcept;
/**
* Like Schedule(), but is a no-op if there is a due time
* earlier than the given one.
*/
void ScheduleEarlier(Event::Duration d) noexcept;
void Cancel() noexcept { void Cancel() noexcept {
unlink(); unlink();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment