[Kernel] Enable RUNNING status in thread.
This commit is contained in:
parent
83b67ec3e2
commit
de624c52c1
|
@ -265,6 +265,7 @@ void rt_system_scheduler_start(void)
|
||||||
#endif /*RT_USING_SMP*/
|
#endif /*RT_USING_SMP*/
|
||||||
|
|
||||||
rt_schedule_remove_thread(to_thread);
|
rt_schedule_remove_thread(to_thread);
|
||||||
|
to_thread->stat = RT_THREAD_RUNNING;
|
||||||
|
|
||||||
/* switch to new thread */
|
/* switch to new thread */
|
||||||
#ifdef RT_USING_SMP
|
#ifdef RT_USING_SMP
|
||||||
|
@ -311,7 +312,7 @@ void rt_schedule(void)
|
||||||
int cpu_id;
|
int cpu_id;
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
cpu_id = rt_hw_cpu_id();
|
cpu_id = rt_hw_cpu_id();
|
||||||
pcpu = rt_cpu_index(cpu_id);
|
pcpu = rt_cpu_index(cpu_id);
|
||||||
|
@ -330,7 +331,7 @@ void rt_schedule(void)
|
||||||
{
|
{
|
||||||
to_thread = _get_highest_priority_thread(&highest_ready_priority);
|
to_thread = _get_highest_priority_thread(&highest_ready_priority);
|
||||||
current_thread->oncpu = RT_CPU_DETACHED;
|
current_thread->oncpu = RT_CPU_DETACHED;
|
||||||
if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
|
if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
|
||||||
{
|
{
|
||||||
if (current_thread->current_priority < highest_ready_priority)
|
if (current_thread->current_priority < highest_ready_priority)
|
||||||
{
|
{
|
||||||
|
@ -350,6 +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;
|
||||||
|
|
||||||
/* switch to new thread */
|
/* switch to new thread */
|
||||||
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
||||||
|
@ -414,7 +416,7 @@ void rt_schedule(void)
|
||||||
|
|
||||||
to_thread = _get_highest_priority_thread(&highest_ready_priority);
|
to_thread = _get_highest_priority_thread(&highest_ready_priority);
|
||||||
|
|
||||||
if ((rt_current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
|
if ((rt_current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
|
||||||
{
|
{
|
||||||
if (rt_current_thread->current_priority < highest_ready_priority)
|
if (rt_current_thread->current_priority < highest_ready_priority)
|
||||||
{
|
{
|
||||||
|
@ -441,6 +443,7 @@ void rt_schedule(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_schedule_remove_thread(to_thread);
|
rt_schedule_remove_thread(to_thread);
|
||||||
|
to_thread->stat = RT_THREAD_RUNNING;
|
||||||
|
|
||||||
/* switch to new thread */
|
/* switch to new thread */
|
||||||
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
||||||
|
@ -482,6 +485,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,7 +535,7 @@ void rt_scheduler_do_irq_switch(void *context)
|
||||||
{
|
{
|
||||||
to_thread = _get_highest_priority_thread(&highest_ready_priority);
|
to_thread = _get_highest_priority_thread(&highest_ready_priority);
|
||||||
current_thread->oncpu = RT_CPU_DETACHED;
|
current_thread->oncpu = RT_CPU_DETACHED;
|
||||||
if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
|
if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
|
||||||
{
|
{
|
||||||
if (current_thread->current_priority < highest_ready_priority)
|
if (current_thread->current_priority < highest_ready_priority)
|
||||||
{
|
{
|
||||||
|
@ -552,6 +556,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;
|
||||||
|
|
||||||
#ifdef RT_USING_OVERFLOW_CHECK
|
#ifdef RT_USING_OVERFLOW_CHECK
|
||||||
_rt_scheduler_stack_check(to_thread);
|
_rt_scheduler_stack_check(to_thread);
|
||||||
|
|
14
src/thread.c
14
src/thread.c
|
@ -655,6 +655,7 @@ RTM_EXPORT(rt_thread_control);
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_thread_suspend(rt_thread_t thread)
|
rt_err_t rt_thread_suspend(rt_thread_t thread)
|
||||||
{
|
{
|
||||||
|
register rt_base_t stat;
|
||||||
register rt_base_t temp;
|
register rt_base_t temp;
|
||||||
|
|
||||||
/* thread check */
|
/* thread check */
|
||||||
|
@ -663,22 +664,25 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
|
||||||
|
|
||||||
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: %s\n", thread->name));
|
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: %s\n", thread->name));
|
||||||
|
|
||||||
if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_READY)
|
stat = thread->stat & RT_THREAD_STAT_MASK;
|
||||||
|
if ((stat != RT_THREAD_READY) && (stat != RT_THREAD_RUNNING))
|
||||||
{
|
{
|
||||||
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: thread disorder, 0x%2x\n",
|
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: thread disorder, 0x%2x\n",
|
||||||
thread->stat));
|
thread->stat));
|
||||||
|
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RT_ASSERT(thread == rt_thread_self());
|
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
temp = rt_hw_interrupt_disable();
|
temp = rt_hw_interrupt_disable();
|
||||||
|
if (stat == RT_THREAD_RUNNING)
|
||||||
|
{
|
||||||
|
/* not suspend running status thread on other core */
|
||||||
|
RT_ASSERT(thread == rt_thread_self());
|
||||||
|
}
|
||||||
|
|
||||||
/* change thread stat */
|
/* change thread stat */
|
||||||
thread->stat = RT_THREAD_SUSPEND | (thread->stat & ~RT_THREAD_STAT_MASK);
|
|
||||||
rt_schedule_remove_thread(thread);
|
rt_schedule_remove_thread(thread);
|
||||||
|
thread->stat = RT_THREAD_SUSPEND | (thread->stat & ~RT_THREAD_STAT_MASK);
|
||||||
|
|
||||||
/* stop thread timer anyway */
|
/* stop thread timer anyway */
|
||||||
rt_timer_stop(&(thread->thread_timer));
|
rt_timer_stop(&(thread->thread_timer));
|
||||||
|
|
|
@ -399,7 +399,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||||
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
|
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
|
||||||
{
|
{
|
||||||
/* check whether timer thread is ready */
|
/* check whether timer thread is ready */
|
||||||
if ((timer_thread.stat & RT_THREAD_STAT_MASK) != RT_THREAD_READY)
|
if ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
|
||||||
{
|
{
|
||||||
/* resume timer thread to check soft timer */
|
/* resume timer thread to check soft timer */
|
||||||
rt_thread_resume(&timer_thread);
|
rt_thread_resume(&timer_thread);
|
||||||
|
|
Loading…
Reference in New Issue