From 911f99e2d6222332e5ad3d2cfbd073592d3d0cb8 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 17 Jul 2024 13:41:04 -0400 Subject: [PATCH] kernel/timer: Rename "last" to "previous". It points to the previous list item, not the last (final) one. No functional change intended, but improves code readability. --- src/system/kernel/timer.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/system/kernel/timer.cpp b/src/system/kernel/timer.cpp index dfb1193a78..516b478d82 100644 --- a/src/system/kernel/timer.cpp +++ b/src/system/kernel/timer.cpp @@ -72,17 +72,17 @@ static void add_event_to_list(timer* event, timer* volatile* list) { timer* next; - timer* last = NULL; + timer* previous = NULL; // stick it in the event list - for (next = *list; next; last = next, next = (timer*)next->next) { + for (next = *list; next != NULL; previous = next, next = (timer*)next->next) { if ((bigtime_t)next->schedule_time >= (bigtime_t)event->schedule_time) break; } - if (last != NULL) { - event->next = last->next; - last->next = event; + if (previous != NULL) { + event->next = previous->next; + previous->next = event; } else { event->next = next; *list = event; @@ -282,13 +282,13 @@ timer_interrupt() acquire_spinlock(spinlock); if ((mode & ~B_TIMER_FLAGS) == B_PERIODIC_TIMER - && cpuData.current_event != NULL) { + && cpuData.current_event != NULL) { // we need to adjust it and add it back to the list event->schedule_time += event->period; // If the new schedule time is a full interval or more in the past, // skip ticks. - bigtime_t now = system_time(); + bigtime_t now = system_time(); if (now >= event->schedule_time + event->period) { // pick the closest tick in the past event->schedule_time = now @@ -299,7 +299,6 @@ timer_interrupt() } cpuData.current_event = NULL; - event = cpuData.events; } @@ -400,20 +399,20 @@ cancel_timer(timer* event) if (event != cpuData.current_event) { // The timer hook is not yet being executed. timer* current = cpuData.events; - timer* last = NULL; + timer* previous = NULL; while (current != NULL) { if (current == event) { // we found it - if (last == NULL) + if (previous == NULL) cpuData.events = current->next; else - last->next = current->next; + previous->next = current->next; current->next = NULL; // break out of the whole thing break; } - last = current; + previous = current; current = current->next; }