Allow a TimerHandler to cancel itself
The new test failed with ShmEventLoop before.
PhasedLoopHandlers have even bigger problems with this kind of usage,
but those aren't usually adjusted while running so it's not as big of a
deal.
Change-Id: I0715f9550fd099647ec0bf52372fbf9c078cc227
diff --git a/aos/events/event_loop_param_test.cc b/aos/events/event_loop_param_test.cc
index 979de74..248dcd3 100644
--- a/aos/events/event_loop_param_test.cc
+++ b/aos/events/event_loop_param_test.cc
@@ -1090,6 +1090,28 @@
EXPECT_EQ(iteration_list.size(), 3);
}
+// Verify that a timer can disable itself.
+//
+// TODO(Brian): Do something similar with phased loops, both with a quick
+// handler and a handler that would miss a cycle except it got deferred. Current
+// behavior doing that is a mess.
+TEST_P(AbstractEventLoopTest, TimerDisableSelf) {
+ auto loop = MakePrimary();
+
+ int count = 0;
+ aos::TimerHandler *test_timer;
+ test_timer = loop->AddTimer([&count, &test_timer]() {
+ ++count;
+ test_timer->Disable();
+ });
+
+ test_timer->Setup(loop->monotonic_now(), ::std::chrono::milliseconds(20));
+ EndEventLoop(loop.get(), ::std::chrono::milliseconds(80));
+ Run();
+
+ EXPECT_EQ(count, 1);
+}
+
// Verify that we can disable a timer during execution of another timer
// scheduled for the same time, with one ordering of creation for the timers.
//