more deterministic on timer

If two timer will timeout at the same tick, the one started later will
be called later. I've tested the patch on simulator and it _seems_ OK.

Reported-by: xdzy on the forum and delin17 <delin17@qq.com>
This commit is contained in:
Grissiom 2013-01-17 16:00:19 +08:00
parent 250fd1082b
commit 0001344105
1 changed files with 9 additions and 3 deletions

View File

@ -276,9 +276,15 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* /*
* It supposes that the new tick shall less than the half duration of * It supposes that the new tick shall less than the half duration of
* tick max. * tick max. And if we have two timers that timeout at the same time,
* it's prefered that the timer inserted early get called early.
*/ */
if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX / 2) if ((t->timeout_tick - timer->timeout_tick) == 0)
{
rt_list_insert_after(n, &(timer->list));
break;
}
else if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX / 2)
{ {
rt_list_insert_before(n, &(timer->list)); rt_list_insert_before(n, &(timer->list));
break; break;