event/FineTimerEvent: add SetDue(), ScheduleCurrent()
This commit is contained in:
parent
9383ceac30
commit
b9daeef524
@ -5,13 +5,29 @@
|
|||||||
#include "FineTimerEvent.hxx"
|
#include "FineTimerEvent.hxx"
|
||||||
#include "Loop.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
|
void
|
||||||
FineTimerEvent::Schedule(Event::Duration d) noexcept
|
FineTimerEvent::Schedule(Event::Duration d) noexcept
|
||||||
{
|
{
|
||||||
Cancel();
|
Cancel();
|
||||||
|
|
||||||
due = loop.SteadyNow() + d;
|
SetDue(d);
|
||||||
loop.Insert(*this);
|
ScheduleCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -26,6 +42,6 @@ FineTimerEvent::ScheduleEarlier(Event::Duration d) noexcept
|
|||||||
Cancel();
|
Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
due = new_due;
|
SetDue(due);
|
||||||
loop.Insert(*this);
|
ScheduleCurrent();
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <boost/intrusive/set_hook.hpp>
|
#include <boost/intrusive/set_hook.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,6 +64,24 @@ public:
|
|||||||
return due;
|
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?
|
* Was this timer scheduled?
|
||||||
*/
|
*/
|
||||||
@ -69,6 +89,13 @@ public:
|
|||||||
return is_linked();
|
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;
|
void Schedule(Event::Duration d) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user