Skip to content

Commit

Permalink
Fix #274: Avoid possible deadlock of timer callback
Browse files Browse the repository at this point in the history
If the tick_time from the wait routine was perpetually
greater than the interval time, eventually the wait_time
became such that it was always below zero.  Once this
occurs, application callbacks would cease entirely.

To avoid this, run the callback condition in a loop
for periodic timers only (not for one-shot config).
  • Loading branch information
jphickey committed Oct 23, 2019
1 parent ad88aa1 commit cf96c46
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/os/shared/osapi-timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id)
timecb = &OS_timecb_table[curr_cb_local_id];
saved_wait_time = timecb->wait_time;
timecb->wait_time -= tick_time;
if (timecb->wait_time <= 0)
while (timecb->wait_time <= 0)
{
timecb->wait_time += timecb->interval_time;

Expand All @@ -519,6 +519,14 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id)
{
(*timecb->callback_ptr)(curr_cb_public_id, timecb->callback_arg);
}

/*
* Do not repeat the loop unless interval_time is configured.
*/
if (timecb->interval_time <= 0)
{
break;
}
}
curr_cb_local_id = timecb->next_ref;
}
Expand Down

0 comments on commit cf96c46

Please sign in to comment.