From d4c21e514c8f4e0f62a08bcec569bdb0df09d7b7 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 17 Nov 2023 16:53:57 -0500 Subject: [PATCH] only: refactoring: reduce guard duplication --- .../controllers/system/timer/event_queue.cpp | 20 ++++--------------- .../controllers/system/timer/event_queue.h | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index f336962b55..487d66efd9 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -28,9 +28,7 @@ extern bool verboseMode; bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s action) { ScopePerf perf(PE::EventQueueInsertTask); -#if EFI_UNIT_TEST assertListIsSorted(); -#endif /* EFI_UNIT_TEST */ efiAssert(ObdCode::CUSTOM_ERR_ASSERT, action.getCallback() != NULL, "NULL callback", false); // please note that simulator does not use this code at all - simulator uses signal_executor_sleep @@ -51,9 +49,7 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s if (head == NULL || timeX < head->momentX) { // here we insert into head of the linked list LL_PREPEND2(head, scheduling, nextScheduling_s); -#if EFI_UNIT_TEST assertListIsSorted(); -#endif /* EFI_UNIT_TEST */ return true; } else { // here we know we are not in the head of the list, let's find the position - linear search @@ -64,17 +60,13 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s scheduling->nextScheduling_s = insertPosition->nextScheduling_s; insertPosition->nextScheduling_s = scheduling; -#if EFI_UNIT_TEST assertListIsSorted(); -#endif /* EFI_UNIT_TEST */ return false; } } void EventQueue::remove(scheduling_s* scheduling) { -#if EFI_UNIT_TEST - assertListIsSorted(); -#endif /* EFI_UNIT_TEST */ + assertListIsSorted(); // Special case: event isn't scheduled, so don't cancel it if (!scheduling->action) { @@ -117,9 +109,7 @@ void EventQueue::remove(scheduling_s* scheduling) { current->action = {}; } -#if EFI_UNIT_TEST assertListIsSorted(); -#endif /* EFI_UNIT_TEST */ } /** @@ -162,9 +152,7 @@ int EventQueue::executeAll(efitick_t now) { int executionCounter = 0; -#if EFI_UNIT_TEST assertListIsSorted(); -#endif bool didExecute; do { @@ -220,10 +208,7 @@ bool EventQueue::executeOne(efitick_t now) { action.execute(); } -#if EFI_UNIT_TEST - // (tests only) Ensure we didn't break anything assertListIsSorted(); -#endif return true; } @@ -236,11 +221,14 @@ int EventQueue::size(void) const { } void EventQueue::assertListIsSorted() const { +#if EFI_UNIT_TEST + // (tests only) Ensure we didn't break anything scheduling_s *current = head; while (current != NULL && current->nextScheduling_s != NULL) { efiAssertVoid(ObdCode::CUSTOM_ERR_6623, current->momentX <= current->nextScheduling_s->momentX, "list order"); current = current->nextScheduling_s; } +#endif } scheduling_s * EventQueue::getHead() { diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index f188beb8f8..a5c02f8c1c 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -60,8 +60,8 @@ public: int size(void) const; scheduling_s *getElementAtIndexForUnitText(int index); scheduling_s * getHead(); - void assertListIsSorted() const; private: + void assertListIsSorted() const; /** * this list is sorted */