diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index c69397c532..7275fc8d77 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -209,5 +209,18 @@ scheduling_s *EventQueue::getElementAtIndexForUnitText(int index) { } void EventQueue::clear(void) { + // Flush the queue, resetting all scheduling_s as though we'd executed them + while(head) { + auto x = head; + // link next element to head + head = x->nextScheduling_s; + + // Reset this element + x->momentX = 0; + x->isScheduled = false; + x->nextScheduling_s = nullptr; + x->action = {}; + } + head = nullptr; } diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp index 3b8ca5bd4e..38b24fb964 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -10,6 +10,11 @@ bool_t debugSignalExecutor = false; extern bool verboseMode; +TestExecutor::~TestExecutor() { + // Flush the queue and reset all scheduling_s at the end of a test's execution + clear(); +} + void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) { if (debugSignalExecutor) { printf("scheduleTask %d\r\n", delayUs); diff --git a/unit_tests/global_execution_queue.h b/unit_tests/global_execution_queue.h index f52cf0875a..8d7d0e3fc7 100644 --- a/unit_tests/global_execution_queue.h +++ b/unit_tests/global_execution_queue.h @@ -12,6 +12,8 @@ class TestExecutor : public ExecutorInterface { public: + ~TestExecutor(); + void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override; void scheduleByTimestampNt(scheduling_s *scheduling, efitick_t timeNt, action_s action) override; void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override;