Skip to content

Commit 201b322

Browse files
committed
event/CoarseTimerEvent: add methods SetDue(), ScheduleCurrent()
FineTimerEvent has these already.
1 parent 365d657 commit 201b322

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

src/event/CoarseTimerEvent.cxx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
#include "CoarseTimerEvent.hxx"
66
#include "Loop.hxx"
77

8+
void
9+
CoarseTimerEvent::SetDue(Event::Duration d) noexcept
10+
{
11+
assert(!IsPending());
12+
13+
SetDue(loop.SteadyNow() + d);
14+
}
15+
16+
void
17+
CoarseTimerEvent::ScheduleCurrent() noexcept
18+
{
19+
assert(!IsPending());
20+
21+
loop.Insert(*this);
22+
}
23+
824
void
925
CoarseTimerEvent::Schedule(Event::Duration d) noexcept
1026
{
1127
Cancel();
1228

13-
due = loop.SteadyNow() + d;
14-
loop.Insert(*this);
29+
SetDue(d);
30+
ScheduleCurrent();
1531
}
1632

1733
void
@@ -26,6 +42,7 @@ CoarseTimerEvent::ScheduleEarlier(Event::Duration d) noexcept
2642
Cancel();
2743
}
2844

29-
due = new_due;
30-
loop.Insert(*this);
45+
SetDue(new_due);
46+
ScheduleCurrent();
47+
3148
}

src/event/CoarseTimerEvent.hxx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,38 @@ public:
5151
return due;
5252
}
5353

54+
/**
55+
* Set the due time as an absolute time point. This can be
56+
* done to prepare an eventual ScheduleCurrent() call. Must
57+
* not be called while the timer is already scheduled.
58+
*/
59+
void SetDue(Event::TimePoint _due) noexcept {
60+
assert(!IsPending());
61+
62+
due = _due;
63+
}
64+
65+
/**
66+
* Set the due time as a duration relative to now. This can
67+
* done to prepare an eventual ScheduleCurrent() call. Must
68+
* not be called while the timer is already scheduled.
69+
*/
70+
void SetDue(Event::Duration d) noexcept;
71+
5472
/**
5573
* Was this timer scheduled?
5674
*/
5775
bool IsPending() const noexcept {
5876
return is_linked();
5977
}
6078

79+
/**
80+
* Schedule the timer at the due time that was already set;
81+
* either by SetDue() or by a Schedule() call that was already
82+
* canceled.
83+
*/
84+
void ScheduleCurrent() noexcept;
85+
6186
void Schedule(Event::Duration d) noexcept;
6287

6388
/**

0 commit comments

Comments
 (0)