event queue shadowing

This commit is contained in:
Matthew Kennedy 2023-11-01 16:02:34 -07:00
parent 1aa4d5d66e
commit 9c3207f5ea
2 changed files with 25 additions and 25 deletions

View File

@ -22,7 +22,7 @@ extern bool verboseMode;
#endif /* EFI_UNIT_TEST */
EventQueue::EventQueue(efitick_t lateDelay)
: lateDelay(lateDelay)
: m_lateDelay(lateDelay)
{
for (size_t i = 0; i < efi::size(m_pool); i++) {
tryReturnScheduling(&m_pool[i]);
@ -97,16 +97,16 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s
scheduling->momentX = timeX;
scheduling->action = action;
if (head == NULL || timeX < head->momentX) {
if (!m_head || timeX < m_head->momentX) {
// here we insert into head of the linked list
LL_PREPEND2(head, scheduling, nextScheduling_s);
LL_PREPEND2(m_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
scheduling_s *insertPosition = head;
scheduling_s *insertPosition = m_head;
while (insertPosition->nextScheduling_s != NULL && insertPosition->nextScheduling_s->momentX < timeX) {
insertPosition = insertPosition->nextScheduling_s;
}
@ -131,17 +131,17 @@ void EventQueue::remove(scheduling_s* scheduling) {
}
// Special case: empty list, nothing to do
if (!head) {
if (!m_head) {
return;
}
// Special case: is the item to remove at the head?
if (scheduling == head) {
head = head->nextScheduling_s;
if (scheduling == m_head) {
m_head = m_head->nextScheduling_s;
scheduling->nextScheduling_s = nullptr;
scheduling->action = {};
} else {
auto prev = head; // keep track of the element before the one to remove, so we can link around it
auto prev = m_head; // keep track of the element before the one to remove, so we can link around it
auto current = prev->nextScheduling_s;
// Find our element
@ -178,8 +178,8 @@ void EventQueue::remove(scheduling_s* scheduling) {
* @return Get the timestamp of the soonest pending action, skipping all the actions in the past
*/
expected<efitick_t> EventQueue::getNextEventTime(efitick_t nowX) const {
if (head != NULL) {
if (head->momentX <= nowX) {
if (m_head) {
if (m_head->momentX <= nowX) {
/**
* We are here if action timestamp is in the past. We should rarely be here since this 'getNextEventTime()' is
* always invoked by 'scheduleTimerCallback' which is always invoked right after 'executeAllPendingActions' - but still,
@ -188,9 +188,9 @@ expected<efitick_t> EventQueue::getNextEventTime(efitick_t nowX) const {
* looks like we end up here after 'writeconfig' (which freezes the firmware) - we are late
* for the next scheduled event
*/
return nowX + lateDelay;
return nowX + m_lateDelay;
} else {
return head->momentX;
return m_head->momentX;
}
}
@ -227,7 +227,7 @@ int EventQueue::executeAll(efitick_t now) {
bool EventQueue::executeOne(efitick_t now) {
// Read the head every time - a previously executed event could
// have inserted something new at the head
scheduling_s* current = head;
scheduling_s* current = m_head;
// Queue is empty - bail
if (!current) {
@ -240,7 +240,7 @@ bool EventQueue::executeOne(efitick_t now) {
// resetting the timer and scheduling an new interrupt is greater than just
// waiting for the time to arrive. On current CPUs, this is reasonable to set
// around 10 microseconds.
if (current->momentX > now + lateDelay) {
if (current->momentX > now + m_lateDelay) {
return false;
}
@ -252,7 +252,7 @@ bool EventQueue::executeOne(efitick_t now) {
}
// step the head forward, unlink this element, clear scheduled flag
head = current->nextScheduling_s;
m_head = current->nextScheduling_s;
current->nextScheduling_s = nullptr;
// Grab the action but clear it in the event so we can reschedule from the action's execution
@ -283,12 +283,12 @@ bool EventQueue::executeOne(efitick_t now) {
int EventQueue::size(void) const {
scheduling_s *tmp;
int result;
LL_COUNT2(head, tmp, result, nextScheduling_s);
LL_COUNT2(m_head, tmp, result, nextScheduling_s);
return result;
}
void EventQueue::assertListIsSorted() const {
scheduling_s *current = head;
scheduling_s *current = m_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;
@ -296,14 +296,14 @@ void EventQueue::assertListIsSorted() const {
}
scheduling_s * EventQueue::getHead() {
return head;
return m_head;
}
// todo: reduce code duplication with another 'getElementAtIndexForUnitText'
scheduling_s *EventQueue::getElementAtIndexForUnitText(int index) {
scheduling_s * current;
LL_FOREACH2(head, current, nextScheduling_s)
LL_FOREACH2(m_head, current, nextScheduling_s)
{
if (index == 0)
return current;
@ -315,10 +315,10 @@ 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;
while(m_head) {
auto x = m_head;
// link next element to head
head = x->nextScheduling_s;
m_head = x->nextScheduling_s;
// Reset this element
x->momentX = 0;
@ -326,5 +326,5 @@ void EventQueue::clear(void) {
x->action = {};
}
head = nullptr;
m_head = nullptr;
}

View File

@ -68,8 +68,8 @@ private:
/**
* this list is sorted
*/
scheduling_s *head = nullptr;
const efitick_t lateDelay;
scheduling_s *m_head = nullptr;
const efitick_t m_lateDelay;
scheduling_s* m_freelist = nullptr;
scheduling_s m_pool[64];