diff --git a/kernel/include/kswap.h b/kernel/include/kswap.h index a12e14b29ad..67bf94b4b2a 100644 --- a/kernel/include/kswap.h +++ b/kernel/include/kswap.h @@ -44,7 +44,7 @@ void _smp_release_global_lock(struct k_thread *thread); static inline unsigned int _Swap(unsigned int key) { struct k_thread *new_thread, *old_thread; - int ret; + int ret = 0; old_thread = _current; @@ -57,22 +57,24 @@ static inline unsigned int _Swap(unsigned int key) new_thread = _get_next_ready_thread(); - old_thread->swap_retval = -EAGAIN; + if (new_thread != old_thread) { + old_thread->swap_retval = -EAGAIN; #ifdef CONFIG_SMP - old_thread->base.active = 0; - new_thread->base.active = 1; + old_thread->base.active = 0; + new_thread->base.active = 1; - new_thread->base.cpu = _arch_curr_cpu()->id; + new_thread->base.cpu = _arch_curr_cpu()->id; - _smp_release_global_lock(new_thread); + _smp_release_global_lock(new_thread); #endif - _current = new_thread; - _arch_switch(new_thread->switch_handle, - &old_thread->switch_handle); + _current = new_thread; + _arch_switch(new_thread->switch_handle, + &old_thread->switch_handle); - ret = _current->swap_retval; + ret = _current->swap_retval; + } irq_unlock(key);