Skip to content

Commit aeff91b

Browse files
authored
Merge pull request #3769 from jesven/fix_yield
解决yield操作不能及时释放cpu的问题
2 parents c758168 + 3ed84b8 commit aeff91b

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/clock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ void rt_tick_increase(void)
9191

9292
thread->stat |= RT_THREAD_STAT_YIELD;
9393

94-
/* yield */
95-
rt_thread_yield();
94+
rt_schedule();
9695
}
9796

9897
/* check timer */

src/scheduler.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ void rt_schedule(void)
346346
}
347347
else
348348
{
349-
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
350349
rt_schedule_insert_thread(current_thread);
351350
}
351+
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
352352
}
353353
to_thread->oncpu = cpu_id;
354354
if (to_thread != current_thread)
@@ -444,9 +444,9 @@ void rt_schedule(void)
444444
}
445445
else
446446
{
447-
rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
448447
need_insert_from_thread = 1;
449448
}
449+
rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
450450
}
451451

452452
if (to_thread != rt_current_thread)
@@ -595,9 +595,9 @@ void rt_scheduler_do_irq_switch(void *context)
595595
}
596596
else
597597
{
598-
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
599598
rt_schedule_insert_thread(current_thread);
600599
}
600+
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
601601
}
602602
to_thread->oncpu = cpu_id;
603603
if (to_thread != current_thread)

src/thread.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,15 @@ RTM_EXPORT(rt_thread_delete);
478478
*/
479479
rt_err_t rt_thread_yield(void)
480480
{
481+
struct rt_thread *thread;
482+
rt_base_t lock;
483+
484+
thread = rt_thread_self();
485+
lock = rt_hw_interrupt_disable();
486+
thread->remaining_tick = thread->init_tick;
487+
thread->stat |= RT_THREAD_STAT_YIELD;
481488
rt_schedule();
489+
rt_hw_interrupt_enable(lock);
482490

483491
return RT_EOK;
484492
}

0 commit comments

Comments
 (0)