diff --git a/arch/xtensa/include/kernel_arch_func.h b/arch/xtensa/include/kernel_arch_func.h index ddbc948f600..fd8792ca40d 100644 --- a/arch/xtensa/include/kernel_arch_func.h +++ b/arch/xtensa/include/kernel_arch_func.h @@ -78,11 +78,13 @@ static ALWAYS_INLINE void kernel_arch_init(void) * * @return N/A */ +#if !CONFIG_USE_SWITCH static ALWAYS_INLINE void _set_thread_return_value(struct k_thread *thread, unsigned int value) { thread->callee_saved.retval = value; } +#endif extern void k_cpu_atomic_idle(unsigned int imask); diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index 6f679d62f1d..47febcac8f6 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -75,6 +75,7 @@ extern void _check_stack_sentinel(void); static inline unsigned int _Swap(unsigned int key) { struct k_thread *new_thread, *old_thread; + int ret; old_thread = _kernel.current; @@ -89,9 +90,11 @@ static inline unsigned int _Swap(unsigned int key) _arch_switch(new_thread->switch_handle, &old_thread->switch_handle); + ret = _kernel.current->swap_retval; + irq_unlock(key); - return _kernel.current->swap_retval; + return ret; } #else /* !CONFIG_USE_SWITCH */ diff --git a/kernel/include/kernel_structs.h b/kernel/include/kernel_structs.h index 86a53cb669b..dbe3f104362 100644 --- a/kernel/include/kernel_structs.h +++ b/kernel/include/kernel_structs.h @@ -138,6 +138,17 @@ extern struct _kernel _kernel; #include +#if CONFIG_USE_SWITCH +/* This is a arch function traditionally, but when the switch-based + * _Swap() is in use it's a simple inline provided by the kernel. + */ +static ALWAYS_INLINE void +_set_thread_return_value(struct k_thread *thread, unsigned int value) +{ + thread->swap_retval = value; +} +#endif + static ALWAYS_INLINE void _set_thread_return_value_with_data(struct k_thread *thread, unsigned int value,