提交 ea4082b7 编写于 作者: B bernard.xiong@gmail.com

fix the next timeout issue in soft timer

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2484 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 b2da1370
......@@ -17,6 +17,7 @@
* 2009-11-11 LiJin add soft timer
* 2010-05-12 Bernard fix the timer check bug.
* 2010-11-02 Charlie re-implement tick overflow issue
* 2012-12-15 Bernard fix the next timeout issue in soft timer
*/
#include <rtthread.h>
......@@ -26,6 +27,14 @@
static rt_list_t rt_timer_list = RT_LIST_OBJECT_INIT(rt_timer_list);
#ifdef RT_USING_TIMER_SOFT
#ifndef RT_TIMER_THREAD_STACK_SIZE
#define RT_TIMER_THREAD_STACK_SIZE 512
#endif
#ifndef RT_TIMER_THREAD_PRIO
#define RT_TIMER_THREAD_PRIO 0
#endif
/* soft timer list */
static rt_list_t rt_soft_timer_list;
static struct rt_thread timer_thread;
......@@ -506,16 +515,28 @@ static void rt_thread_timer_entry(void *parameter)
while (1)
{
/* get the next timeout tick */
next_timeout = rt_timer_list_next_timeout(&rt_soft_timer_list);
if (next_timeout == RT_TICK_MAX)
{
/* no software timer exist, suspend self. */
rt_thread_suspend(rt_thread_self());
rt_schedule();
}
else
{
rt_tick_t current_tick;
/* get current tick */
current_tick = rt_tick_get();
if ((next_timeout - current_tick) < RT_TICK_MAX/2)
{
/* get the delta timeout tick */
next_timeout = next_timeout - current_tick;
rt_thread_delay(next_timeout);
}
}
/* lock scheduler */
rt_enter_critical();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册