arch: riscv: make arch_current_thread_set() safer

Use the "do { } while (0)" construct so the macro behaves like an actual
C statement in all cases. Also evaluate the macro argument only once.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre
2024-11-29 17:34:47 -05:00
committed by Fabio Baltieri
parent 55602a5b6b
commit 132fa83ed4

View File

@@ -32,10 +32,9 @@ register struct k_thread *__arch_current_thread __asm__("gp");
#define arch_current_thread() __arch_current_thread
#define arch_current_thread_set(thread) \
{ \
_current_cpu->current = thread; \
__arch_current_thread = (thread); \
}
do { \
_current_cpu->current = __arch_current_thread = (thread); \
} while (0)
#endif /* CONFIG_RISCV_CURRENT_VIA_GP */
static ALWAYS_INLINE unsigned int arch_num_cpus(void)