event/FineTimerEvent: add SetDue(), ScheduleCurrent()

This commit is contained in:
Max Kellermann 2023-11-10 12:27:51 +01:00 committed by Max Kellermann
parent 9383ceac30
commit b9daeef524
2 changed files with 47 additions and 4 deletions

View File

@ -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();
}

View File

@ -14,6 +14,8 @@
#include <boost/intrusive/set_hook.hpp>
#endif
#include <cassert>
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;
/**