Skip to content

Commit

Permalink
fix bug introduced in last change which could call timer in wrong tas…
Browse files Browse the repository at this point in the history
…k; clean-up
  • Loading branch information
phoddie committed Mar 30, 2022
1 parent a122a5e commit 30a698f
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions modules/base/timer/mc/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ void modTimersExecute(void)
// determine who is firing this time (timers added during this call are ineligible)
modCriticalSectionBegin();
for (walker = gTimers; NULL != walker; walker = walker->next) {
if ((walker->flags & kTimerFlagUnscheduled)
#if MOD_TASKS
|| (task != walker->task)
#endif
)
if (walker->flags & (kTimerFlagUnscheduled | kTimerFlagFire))
continue;
int32_t delta = walker->triggerTime - now;
if (delta <= 0)
Expand All @@ -73,7 +69,11 @@ void modTimersExecute(void)

// service eligible callbacks. then reschedule (repeating) or remove (one shot)
for (walker = gTimers; NULL != walker; ) {
if (!(walker->flags & kTimerFlagFire)) {
if (!(walker->flags & kTimerFlagFire)
#if MOD_TASKS
|| (task != walker->task)
#endif
) {
walker = walker->next;
continue;
}
Expand Down Expand Up @@ -114,17 +114,14 @@ int modTimersNext(void)
modCriticalSectionBegin();

for (walker = gTimers; NULL != walker; walker = walker->next) {
int delta;

if (!walker->cb ||
(walker->flags & kTimerFlagUnscheduled)
if ((walker->flags & kTimerFlagUnscheduled)
#if MOD_TASKS
|| (task != walker->task)
#endif
)
continue;

delta = walker->triggerTime - now;
int32_t delta = walker->triggerTime - now;
if (delta < next) {
if (delta <= 0) {
modCriticalSectionEnd();
Expand Down Expand Up @@ -217,7 +214,7 @@ void modTimerRemove(modTimer timer)

for (walker = gTimers; NULL != walker; prev = walker, walker = walker->next) {
if (timer == walker) {
walker->flags = kTimerFlagUnscheduled;
timer->flags = kTimerFlagUnscheduled;

timer->useCount--;
if (timer->useCount <= 0) {
Expand Down

0 comments on commit 30a698f

Please sign in to comment.