only: refactoring: reduce guard duplication

This commit is contained in:
rusefillc 2023-11-17 16:53:57 -05:00
parent 36ebec3730
commit d4c21e514c
2 changed files with 5 additions and 17 deletions

View File

@ -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() {

View File

@ -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
*/