From db90cb3e0dd33cadbd4fcd49bc1e7298c6969a90 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 11 Jul 2024 16:11:47 -0700 Subject: [PATCH] minor event_queue cleanup --- .../controllers/system/timer/event_queue.cpp | 4 +-- .../controllers/system/timer/event_queue.h | 31 +++---------------- .../system/timer/trigger_scheduler.cpp | 22 ++++++++++++- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index 903ea5f13e..7b6ed8e65e 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -263,7 +263,7 @@ bool EventQueue::executeOne(efitick_t now) { return true; } -int EventQueue::size(void) const { +int EventQueue::size() const { scheduling_s *tmp; int result; LL_COUNT2(m_head, tmp, result, nextScheduling_s); @@ -298,7 +298,7 @@ scheduling_s *EventQueue::getElementAtIndexForUnitText(int index) { return NULL; } -void EventQueue::clear(void) { +void EventQueue::clear() { // Flush the queue, resetting all scheduling_s as though we'd executed them while(m_head) { auto x = m_head; diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index f711eb124b..8eff89a642 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -5,37 +5,14 @@ * @author Andrey Belomutskiy, (c) 2012-2020 */ +#pragma once + #include "scheduler.h" #include "utlist.h" #include -#pragma once - #define QUEUE_LENGTH_LIMIT 1000 -// templates do not accept field names so we use a macro here -#define assertNotInListMethodBody(head, element, field) \ - /* this code is just to validate state, no functional load*/ \ - decltype(head) current; \ - int counter = 0; \ - LL_FOREACH2(head, current, field) { \ - if (++counter > QUEUE_LENGTH_LIMIT) { \ - firmwareError(ObdCode::CUSTOM_ERR_LOOPED_QUEUE, "Looped queue?"); \ - return false; \ - } \ - if (current == element) { \ - /** \ - * for example, this might happen in case of sudden RPM change if event \ - * was not scheduled by angle but was scheduled by time. In case of scheduling \ - * by time with slow RPM the whole next fast revolution might be within the wait period \ - */ \ - warning(ObdCode::CUSTOM_RE_ADDING_INTO_EXECUTION_QUEUE, "re-adding element into event_queue"); \ - return true; \ - } \ - } \ - return false; - - /** * Execution sorted linked list */ @@ -56,8 +33,8 @@ public: bool executeOne(efitick_t now); expected getNextEventTime(efitick_t nowUs) const; - void clear(void); - int size(void) const; + void clear(); + int size() const; scheduling_s *getElementAtIndexForUnitText(int index); scheduling_s * getHead(); diff --git a/firmware/controllers/system/timer/trigger_scheduler.cpp b/firmware/controllers/system/timer/trigger_scheduler.cpp index d18f520702..aa07b83dea 100644 --- a/firmware/controllers/system/timer/trigger_scheduler.cpp +++ b/firmware/controllers/system/timer/trigger_scheduler.cpp @@ -3,7 +3,27 @@ #include "event_queue.h" bool TriggerScheduler::assertNotInList(AngleBasedEvent *head, AngleBasedEvent *element) { - assertNotInListMethodBody(head, element, nextToothEvent) + /* this code is just to validate state, no functional load*/ + decltype(head) current; + int counter = 0; + LL_FOREACH2(head, current, nextToothEvent) { + if (++counter > QUEUE_LENGTH_LIMIT) { + firmwareError(ObdCode::CUSTOM_ERR_LOOPED_QUEUE, "Looped queue?"); + return false; + } + + if (current == element) { + /** + * for example, this might happen in case of sudden RPM change if event + * was not scheduled by angle but was scheduled by time. In case of scheduling + * by time with slow RPM the whole next fast revolution might be within the wait + */ + warning(ObdCode::CUSTOM_RE_ADDING_INTO_EXECUTION_QUEUE, "re-adding element into event_queue"); + return true; + } + } + + return false; } void TriggerScheduler::schedule(AngleBasedEvent* event, angle_t angle, action_s action) {