add rt_thread_idle_excute API.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@830 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-08-05 08:16:30 +00:00
parent 898ad75a7a
commit 2e0352e653
2 changed files with 74 additions and 46 deletions

View File

@ -120,6 +120,7 @@ void rt_thread_idle_init(void);
#ifdef RT_USING_HOOK #ifdef RT_USING_HOOK
void rt_thread_idle_sethook(void (*hook)(void)); void rt_thread_idle_sethook(void (*hook)(void));
#endif #endif
void rt_thread_idle_excute(void);
/* /*
* schedule service * schedule service

View File

@ -52,38 +52,48 @@ void rt_thread_idle_sethook(void (*hook)())
/*@}*/ /*@}*/
#endif #endif
static void rt_thread_idle_entry(void* parameter) /**
* This function will do some things when system idle.
*/
void rt_thread_idle_excute(void)
{ {
while (1)
{
#ifdef RT_USING_HOOK
/* if there is an idle thread hook */
if (rt_thread_idle_hook != RT_NULL) rt_thread_idle_hook();
#endif
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
/* check the defunct thread list */ /* check the defunct thread list */
if (!rt_list_isempty(&rt_thread_defunct)) if (!rt_list_isempty(&rt_thread_defunct))
{ {
rt_base_t lock; rt_base_t lock;
struct rt_thread* thread = rt_list_entry(rt_thread_defunct.next, struct rt_thread, tlist); rt_thread_t thread;
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
rt_module_t module = thread->module_parent; rt_module_t module;
#endif #endif
/* disable interrupt */ /* disable interrupt */
lock = rt_hw_interrupt_disable(); lock = rt_hw_interrupt_disable();
rt_list_remove(&(thread->tlist)); /* re-check whether list is empty */
if (!rt_list_isempty(&rt_thread_defunct))
{
/* get defunct thread */
thread = rt_list_entry(rt_thread_defunct.next, struct rt_thread, tlist);
/* get thread's parent module */
#ifdef RT_USING_MODULE
module = thread->module_parent;
#endif
/* remove defunct thread */
rt_list_remove(&(thread->tlist));
}
else
{
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(lock); rt_hw_interrupt_enable(lock);
/* release thread's stack */ /* may the defunct thread list is removed by others, just return */
rt_free(thread->stack_addr); return;
}
/* delete thread object */ /* enable interrupt */
rt_object_delete((rt_object_t)thread); rt_hw_interrupt_enable(lock);
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
if(module != RT_NULL) if(module != RT_NULL)
@ -105,9 +115,26 @@ static void rt_thread_idle_entry(void* parameter)
} }
} }
#endif #endif
/* release thread's stack */
rt_free(thread->stack_addr);
/* delete thread object */
rt_object_delete((rt_object_t)thread);
} }
#endif #endif
} }
static void rt_thread_idle_entry(void* parameter)
{
while (1)
{
#ifdef RT_USING_HOOK
/* if there is an idle thread hook */
if (rt_thread_idle_hook != RT_NULL) rt_thread_idle_hook();
#endif
rt_thread_idle_excute();
}
} }
/** /**