minor event_queue cleanup

This commit is contained in:
Matthew Kennedy 2024-07-11 16:11:47 -07:00
parent c591b0acc3
commit db90cb3e0d
3 changed files with 27 additions and 30 deletions

View File

@ -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;

View File

@ -5,37 +5,14 @@
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "scheduler.h"
#include "utlist.h"
#include <rusefi/expected.h>
#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<efitick_t> 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();

View File

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