From 2c1449bc812ad55511b8e9464b8ab7fb2bcdee7d Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Sun, 17 Dec 2017 08:53:44 -0800 Subject: [PATCH] kernel, xtensa: Switch-specific thread return value When using _arch_switch() context switching, the thread return value is a generic hook and not provided by the architecture. Signed-off-by: Andy Ross --- arch/xtensa/include/kernel_arch_func.h | 2 ++ kernel/include/kernel_internal.h | 5 ++++- kernel/include/kernel_structs.h | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) 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,