mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-28 05:37:04 +08:00
fix the next timeout issue in soft timer
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2484 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
b2da13707b
commit
ea4082b791
21
src/timer.c
21
src/timer.c
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user