summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2018-02-07 19:53:08 +0800
committerBernard Xiong <[email protected]>2018-02-07 19:55:35 +0800
commit55e2fabbc5a180e3bf3a3f287cd6b5cc81d2fd24 (patch)
tree2b3374284f20ad000fb8b930b72806638534cece
parent4e41b0573b93468c8cfd3425ed2f13c8ec0574f6 (diff)
[kernel] lock scheduler when cleanup thread
-rw-r--r--src/idle.c11
1 files changed, 11 insertions, 0 deletions
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 <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
{