4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-30 06:00:27 +08:00

Merge pull request #3769 from jesven/fix_yield

解决yield操作不能及时释放cpu的问题
This commit is contained in:
Bernard Xiong 2020-10-01 15:46:10 +08:00 committed by GitHub
commit aeff91b2a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -91,8 +91,7 @@ void rt_tick_increase(void)
thread->stat |= RT_THREAD_STAT_YIELD; thread->stat |= RT_THREAD_STAT_YIELD;
/* yield */ rt_schedule();
rt_thread_yield();
} }
/* check timer */ /* check timer */

View File

@ -346,9 +346,9 @@ void rt_schedule(void)
} }
else else
{ {
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
rt_schedule_insert_thread(current_thread); rt_schedule_insert_thread(current_thread);
} }
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
} }
to_thread->oncpu = cpu_id; to_thread->oncpu = cpu_id;
if (to_thread != current_thread) if (to_thread != current_thread)
@ -444,9 +444,9 @@ void rt_schedule(void)
} }
else else
{ {
rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
need_insert_from_thread = 1; need_insert_from_thread = 1;
} }
rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
} }
if (to_thread != rt_current_thread) if (to_thread != rt_current_thread)
@ -595,9 +595,9 @@ void rt_scheduler_do_irq_switch(void *context)
} }
else else
{ {
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
rt_schedule_insert_thread(current_thread); rt_schedule_insert_thread(current_thread);
} }
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
} }
to_thread->oncpu = cpu_id; to_thread->oncpu = cpu_id;
if (to_thread != current_thread) if (to_thread != current_thread)

View File

@ -478,7 +478,15 @@ RTM_EXPORT(rt_thread_delete);
*/ */
rt_err_t rt_thread_yield(void) rt_err_t rt_thread_yield(void)
{ {
struct rt_thread *thread;
rt_base_t lock;
thread = rt_thread_self();
lock = rt_hw_interrupt_disable();
thread->remaining_tick = thread->init_tick;
thread->stat |= RT_THREAD_STAT_YIELD;
rt_schedule(); rt_schedule();
rt_hw_interrupt_enable(lock);
return RT_EOK; return RT_EOK;
} }