diff options
| author | chengxiaohu <[email protected]> | 2019-11-20 23:38:35 +0800 |
|---|---|---|
| committer | chengxiaohu <[email protected]> | 2019-11-20 23:38:35 +0800 |
| commit | 6b8a3469f8cb69d9ee49487c524533a9516ebce1 (patch) | |
| tree | 9b51157878a815b6da9d8d691ac0bbdbb2bc1f64 /src | |
| parent | 2a512f3df0f39790a14f1984c42a97dc0a82ba09 (diff) | |
| parent | 1bf5f67e8a6c9672945d3b0a61e173ce0b6e56d3 (diff) | |
Merge branch 'master' of https://github.com/chengxiaohu/rt-thread
Diffstat (limited to 'src')
| -rw-r--r-- | src/clock.c | 2 | ||||
| -rw-r--r-- | src/scheduler.c | 32 | ||||
| -rw-r--r-- | src/thread.c | 12 |
3 files changed, 34 insertions, 12 deletions
diff --git a/src/clock.c b/src/clock.c index a652282b6e..9b54101363 100644 --- a/src/clock.c +++ b/src/clock.c @@ -89,6 +89,8 @@ void rt_tick_increase(void) /* change to initialized tick */ thread->remaining_tick = thread->init_tick; + thread->stat |= RT_THREAD_STAT_YIELD; + /* yield */ rt_thread_yield(); } diff --git a/src/scheduler.c b/src/scheduler.c index f671a49623..6baaa9627a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -344,8 +344,13 @@ void rt_schedule(void) { to_thread = current_thread; } + else if (current_thread->current_priority == highest_ready_priority && (current_thread->stat & RT_THREAD_STAT_YIELD_MASK) == 0) + { + to_thread = current_thread; + } else { + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } } @@ -379,7 +384,12 @@ void rt_schedule(void) } } + /* enable interrupt */ + rt_hw_interrupt_enable(level); + #ifdef RT_USING_SIGNALS + /* check stat of thread for signal */ + level = rt_hw_interrupt_disable(); if (current_thread->stat & RT_THREAD_STAT_SIGNAL_PENDING) { extern void rt_thread_handle_sig(rt_bool_t clean_state); @@ -395,9 +405,6 @@ void rt_schedule(void) { rt_hw_interrupt_enable(level); } -#else - /* enable interrupt */ - rt_hw_interrupt_enable(level); #endif __exit: @@ -435,8 +442,13 @@ void rt_schedule(void) { to_thread = rt_current_thread; } + else if (rt_current_thread->current_priority == highest_ready_priority && (rt_current_thread->stat & RT_THREAD_STAT_YIELD_MASK) == 0) + { + to_thread = rt_current_thread; + } else { + rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; need_insert_from_thread = 1; } } @@ -477,7 +489,13 @@ void rt_schedule(void) rt_hw_context_switch((rt_ubase_t)&from_thread->sp, (rt_ubase_t)&to_thread->sp); + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + #ifdef RT_USING_SIGNALS + /* check stat of thread for signal */ + level = rt_hw_interrupt_disable(); if (rt_current_thread->stat & RT_THREAD_STAT_SIGNAL_PENDING) { extern void rt_thread_handle_sig(rt_bool_t clean_state); @@ -493,9 +511,6 @@ void rt_schedule(void) { rt_hw_interrupt_enable(level); } -#else - /* enable interrupt */ - rt_hw_interrupt_enable(level); #endif goto __exit; } @@ -578,8 +593,13 @@ void rt_scheduler_do_irq_switch(void *context) { to_thread = current_thread; } + else if (current_thread->current_priority == highest_ready_priority && (current_thread->stat & RT_THREAD_STAT_YIELD_MASK) == 0) + { + to_thread = current_thread; + } else { + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } } diff --git a/src/thread.c b/src/thread.c index a88729e52c..c5f75a1176 100644 --- a/src/thread.c +++ b/src/thread.c @@ -107,11 +107,11 @@ void rt_thread_exit(void) rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); } - /* enable interrupt */ - rt_hw_interrupt_enable(level); - /* switch to next task */ rt_schedule(); + + /* enable interrupt */ + rt_hw_interrupt_enable(level); } static rt_err_t _rt_thread_init(struct rt_thread *thread, @@ -446,12 +446,12 @@ rt_err_t rt_thread_delete(rt_thread_t thread) /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); - /* change stat */ - thread->stat = RT_THREAD_CLOSE; - /* disable interrupt */ lock = rt_hw_interrupt_disable(); + /* change stat */ + thread->stat = RT_THREAD_CLOSE; + /* insert to defunct thread list */ rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); |
