提交 69994ca2 编写于 作者: B Bernard Xiong

[Kernel] Fix rt_schedule_insert_thread issue

When suspend current thread and then enable interrupt, it's possible resume "the current thread" immediately and insert to ready queue. The rt_schedule_insert_thread should change  the status of "current thread" to RUNNING statue.
上级 bef1d557
...@@ -351,7 +351,7 @@ void rt_schedule(void) ...@@ -351,7 +351,7 @@ void rt_schedule(void)
RT_OBJECT_HOOK_CALL(rt_scheduler_hook, (current_thread, to_thread)); RT_OBJECT_HOOK_CALL(rt_scheduler_hook, (current_thread, to_thread));
rt_schedule_remove_thread(to_thread); rt_schedule_remove_thread(to_thread);
to_thread->stat = RT_THREAD_RUNNING; to_thread->stat = RT_THREAD_RUNNING | (to_thread->stat & ~RT_THREAD_STAT_MASK);
/* switch to new thread */ /* switch to new thread */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
...@@ -412,6 +412,7 @@ void rt_schedule(void) ...@@ -412,6 +412,7 @@ void rt_schedule(void)
if (rt_thread_ready_priority_group != 0) if (rt_thread_ready_priority_group != 0)
{ {
/* need_insert_from_thread: need to insert from_thread to ready queue */
int need_insert_from_thread = 0; int need_insert_from_thread = 0;
to_thread = _get_highest_priority_thread(&highest_ready_priority); to_thread = _get_highest_priority_thread(&highest_ready_priority);
...@@ -443,7 +444,7 @@ void rt_schedule(void) ...@@ -443,7 +444,7 @@ void rt_schedule(void)
} }
rt_schedule_remove_thread(to_thread); rt_schedule_remove_thread(to_thread);
to_thread->stat = RT_THREAD_RUNNING; to_thread->stat = RT_THREAD_RUNNING | (to_thread->stat & ~RT_THREAD_STAT_MASK);
/* switch to new thread */ /* switch to new thread */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
...@@ -485,7 +486,7 @@ void rt_schedule(void) ...@@ -485,7 +486,7 @@ void rt_schedule(void)
else else
{ {
rt_schedule_remove_thread(rt_current_thread); rt_schedule_remove_thread(rt_current_thread);
rt_current_thread->stat = RT_THREAD_RUNNING; rt_current_thread->stat = RT_THREAD_RUNNING | (rt_current_thread->stat & ~RT_THREAD_STAT_MASK);
} }
} }
} }
...@@ -556,7 +557,7 @@ void rt_scheduler_do_irq_switch(void *context) ...@@ -556,7 +557,7 @@ void rt_scheduler_do_irq_switch(void *context)
RT_OBJECT_HOOK_CALL(rt_scheduler_hook, (current_thread, to_thread)); RT_OBJECT_HOOK_CALL(rt_scheduler_hook, (current_thread, to_thread));
rt_schedule_remove_thread(to_thread); rt_schedule_remove_thread(to_thread);
to_thread->stat = RT_THREAD_RUNNING; to_thread->stat = RT_THREAD_RUNNING | (to_thread->stat & ~RT_THREAD_STAT_MASK);
#ifdef RT_USING_OVERFLOW_CHECK #ifdef RT_USING_OVERFLOW_CHECK
_rt_scheduler_stack_check(to_thread); _rt_scheduler_stack_check(to_thread);
...@@ -595,14 +596,16 @@ void rt_schedule_insert_thread(struct rt_thread *thread) ...@@ -595,14 +596,16 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
/* disable interrupt */ /* disable interrupt */
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
/* change stat */ /* it should be RUNNING thread */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
if (thread->oncpu != RT_CPU_DETACHED) if (thread->oncpu != RT_CPU_DETACHED)
{ {
thread->stat = RT_THREAD_RUNNING | (thread->stat & ~RT_THREAD_STAT_MASK);
goto __exit; goto __exit;
} }
/* READY thread, insert to ready queue */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
cpu_id = rt_hw_cpu_id(); cpu_id = rt_hw_cpu_id();
bind_cpu = thread->bind_cpu ; bind_cpu = thread->bind_cpu ;
...@@ -655,14 +658,15 @@ void rt_schedule_insert_thread(struct rt_thread *thread) ...@@ -655,14 +658,15 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
/* disable interrupt */ /* disable interrupt */
temp = rt_hw_interrupt_disable(); temp = rt_hw_interrupt_disable();
/* change stat */ /* it's current thread, it should be RUNNING thread */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
if (thread == rt_current_thread) if (thread == rt_current_thread)
{ {
thread->stat = RT_THREAD_RUNNING | (thread->stat & ~RT_THREAD_STAT_MASK);
goto __exit; goto __exit;
} }
/* READY thread, insert to ready queue */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
/* insert thread to ready list */ /* insert thread to ready list */
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]), rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist)); &(thread->tlist));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册