Skip to content

Commit

Permalink
Bugfix: Rp2040 os_timer_setfn() can stall other timers. (#2672)
Browse files Browse the repository at this point in the history
If called on first timer in queue then subsequent timers get disconnected. Must explicitly `disarm` the timer first so it's properly removed from queue. This is consistent with esp8266 behaviour.

Also applied to host timer from whence the code originated.
This bug might explain root cause of #2594, where code hangs during intensive timer usage. Specifically, this issue gets triggered if attempting to change the callback on an active timer. (If the timer is inactive then it's not in the queue so doesn't matter.)
  • Loading branch information
mikee47 authored Oct 12, 2023
1 parent 12cdc8b commit b153bc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Sming/Arch/Host/Components/driver/os_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ void os_timer_disarm(struct os_timer_t* ptimer)

void os_timer_setfn(struct os_timer_t* ptimer, os_timer_func_t* pfunction, void* parg)
{
if(ptimer != nullptr) {
ptimer->timer_func = pfunction;
ptimer->timer_arg = parg;
ptimer->timer_next = reinterpret_cast<os_timer_t*>(-1);
if(ptimer == nullptr) {
return;
}
os_timer_disarm(ptimer);
ptimer->timer_func = pfunction;
ptimer->timer_arg = parg;
}

void os_timer_done(struct os_timer_t* ptimer)
Expand Down
9 changes: 5 additions & 4 deletions Sming/Arch/Rp2040/Components/driver/os_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,12 @@ void IRAM_ATTR os_timer_disarm(struct os_timer_t* ptimer)

void os_timer_setfn(struct os_timer_t* ptimer, os_timer_func_t* pfunction, void* parg)
{
if(ptimer != nullptr) {
ptimer->timer_func = pfunction;
ptimer->timer_arg = parg;
ptimer->timer_next = reinterpret_cast<os_timer_t*>(-1);
if(ptimer == nullptr) {
return;
}
os_timer_disarm(ptimer);
ptimer->timer_func = pfunction;
ptimer->timer_arg = parg;
}

void os_timer_done(struct os_timer_t* ptimer)
Expand Down

0 comments on commit b153bc8

Please sign in to comment.