[kernel] lock scheduler when cleanup thread

This commit is contained in:
Bernard Xiong 2018-02-07 19:53:08 +08:00
parent 4e41b0573b
commit 55e2fabbc5
1 changed files with 11 additions and 0 deletions

View File

@ -25,6 +25,7 @@
* 2013-12-21 Grissiom let rt_thread_idle_excute loop until there is no
* dead thread.
* 2016-08-09 ArdaFu add method to get the handler of the idle thread.
* 2018-02-07 Bernard lock scheduler to protect tid->cleanup.
*/
#include <rthw.h>
@ -123,6 +124,10 @@ void rt_thread_idle_excute(void)
#endif
/* remove defunct thread */
rt_list_remove(&(thread->tlist));
/* lock scheduler to prevent scheduling in cleanup function. */
rt_enter_critical();
/* invoke thread cleanup */
if (thread->cleanup != RT_NULL)
thread->cleanup(thread);
@ -134,11 +139,17 @@ void rt_thread_idle_excute(void)
/* if it's a system object, not delete it */
if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
{
/* unlock scheduler */
rt_exit_critical();
/* enable interrupt */
rt_hw_interrupt_enable(lock);
return;
}
/* unlock scheduler */
rt_exit_critical();
}
else
{