diff --git a/src/event/FineTimerEvent.cxx b/src/event/FineTimerEvent.cxx index 0a092019d..a32be763d 100644 --- a/src/event/FineTimerEvent.cxx +++ b/src/event/FineTimerEvent.cxx @@ -5,13 +5,29 @@ #include "FineTimerEvent.hxx" #include "Loop.hxx" +void +FineTimerEvent::SetDue(Event::Duration d) noexcept +{ + assert(!IsPending()); + + SetDue(loop.SteadyNow() + d); +} + +void +FineTimerEvent::ScheduleCurrent() noexcept +{ + assert(!IsPending()); + + loop.Insert(*this); +} + void FineTimerEvent::Schedule(Event::Duration d) noexcept { Cancel(); - due = loop.SteadyNow() + d; - loop.Insert(*this); + SetDue(d); + ScheduleCurrent(); } void @@ -26,6 +42,6 @@ FineTimerEvent::ScheduleEarlier(Event::Duration d) noexcept Cancel(); } - due = new_due; - loop.Insert(*this); + SetDue(due); + ScheduleCurrent(); } diff --git a/src/event/FineTimerEvent.hxx b/src/event/FineTimerEvent.hxx index bd30c6cb5..e0cd15d94 100644 --- a/src/event/FineTimerEvent.hxx +++ b/src/event/FineTimerEvent.hxx @@ -14,6 +14,8 @@ #include #endif +#include + class EventLoop; /** @@ -62,6 +64,24 @@ public: return due; } + /** + * Set the due time as an absolute time point. This can be + * done to prepare an eventual ScheduleCurrent() call. Must + * not be called while the timer is already scheduled. + */ + void SetDue(Event::TimePoint _due) noexcept { + assert(!IsPending()); + + due = _due; + } + + /** + * Set the due time as a duration relative to now. This can + * done to prepare an eventual ScheduleCurrent() call. Must + * not be called while the timer is already scheduled. + */ + void SetDue(Event::Duration d) noexcept; + /** * Was this timer scheduled? */ @@ -69,6 +89,13 @@ public: return is_linked(); } + /** + * Schedule the timer at the due time that was already set; + * either by SetDue() or by a Schedule() call that was already + * canceled. + */ + void ScheduleCurrent() noexcept; + void Schedule(Event::Duration d) noexcept; /**