From 3ed84b8d03dc9778f1c262278e2b8653de834408 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 24 Jul 2020 21:13:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3yield=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=8F=8A=E6=97=B6=E9=87=8A=E6=94=BEcpu?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 3 +-- src/scheduler.c | 6 +++--- src/thread.c | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/clock.c b/src/clock.c index 97a09ddeaf..a91cd829b6 100644 --- a/src/clock.c +++ b/src/clock.c @@ -91,8 +91,7 @@ void rt_tick_increase(void) thread->stat |= RT_THREAD_STAT_YIELD; - /* yield */ - rt_thread_yield(); + rt_schedule(); } /* check timer */ diff --git a/src/scheduler.c b/src/scheduler.c index 6baaa9627a..d0859e745a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -350,9 +350,9 @@ void rt_schedule(void) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) @@ -448,9 +448,9 @@ void rt_schedule(void) } else { - rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; need_insert_from_thread = 1; } + rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } if (to_thread != rt_current_thread) @@ -599,9 +599,9 @@ void rt_scheduler_do_irq_switch(void *context) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) diff --git a/src/thread.c b/src/thread.c index 715596b132..60aa17f381 100644 --- a/src/thread.c +++ b/src/thread.c @@ -478,7 +478,15 @@ RTM_EXPORT(rt_thread_delete); */ 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_hw_interrupt_enable(lock); return RT_EOK; }