From 55e2fabbc5a180e3bf3a3f287cd6b5cc81d2fd24 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 7 Feb 2018 19:53:08 +0800 Subject: [PATCH] [kernel] lock scheduler when cleanup thread --- src/idle.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/idle.c b/src/idle.c index 68b816f7ed..ecd894b8e2 100644 --- a/src/idle.c +++ b/src/idle.c @@ -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 @@ -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 {