summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2013-01-17 00:28:24 -0800
committerBernard Xiong <[email protected]>2013-01-17 00:28:24 -0800
commit14dbee0082b26bfb6b9acab6c3f4ec2d880c3dcd (patch)
tree7242bd486d7488b846232ddd4c417b1af3cd10eb
parent250fd1082b193f3c4b2d1abe78f68de23e3c25ee (diff)
parent0001344105054ed6c09184db96c1b04eb882fdd0 (diff)
Merge pull request #16 from grissiom/fix-timer
more deterministic on timer
-rw-r--r--src/timer.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/timer.c b/src/timer.c
index a1699dad63..2a27d9d9a8 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -273,12 +273,18 @@ rt_err_t rt_timer_start(rt_timer_t timer)
for (n = timer_list->next; n != timer_list; n = n->next)
{
t = rt_list_entry(n, struct rt_timer, list);
-
+
/*
* 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));
break;