Commit ae074796 authored by Juho Snellman's avatar Juho Snellman

Allow canceling inactive timers

- Mostly for convenience; it's common to cancel timers even if
  you don't know they are running. Without this, such code would
  need a lot of (fragile) checks.
parent 816901d6
......@@ -86,6 +86,14 @@ bool test_single_timer_no_hierarchy() {
timers.advance(5);
EXPECT_INTEQ(count, 4);
// Timer can safely be canceled multiple times.
timers.schedule(&timer, 5);
timer.cancel();
timer.cancel();
EXPECT(!timer.active());
timers.advance(10);
EXPECT_INTEQ(count, 4);
return true;
}
......
......@@ -206,6 +206,11 @@ private:
};
void TimerEventInterface::cancel() {
// It's ok to cancel a timer that's not running.
if (!slot_) {
return;
}
if (this == slot_->events()) {
slot_->pop_event();
} else {
......
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