1 /* 2 * Copyright (c) 2024 Meta Platforms. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_ZEPHYR_ARCH_COMMON_ARCH_INLINES_H_ 8 #define ZEPHYR_INCLUDE_ZEPHYR_ARCH_COMMON_ARCH_INLINES_H_ 9 10 #ifndef ZEPHYR_INCLUDE_ARCH_INLINES_H_ 11 #error "This header shouldn't be included directly" 12 #endif /* ZEPHYR_INCLUDE_ARCH_INLINES_H_ */ 13 14 #ifndef _ASMLANGUAGE 15 16 #include <zephyr/kernel_structs.h> 17 18 #ifndef CONFIG_ARCH_HAS_CUSTOM_CURRENT_IMPL arch_current_thread(void)19static ALWAYS_INLINE struct k_thread *arch_current_thread(void) 20 { 21 #ifdef CONFIG_SMP 22 /* In SMP, arch_current_thread() is a field read from _current_cpu, which 23 * can race with preemption before it is read. We must lock 24 * local interrupts when reading it. 25 */ 26 unsigned int k = arch_irq_lock(); 27 28 struct k_thread *ret = _current_cpu->current; 29 30 arch_irq_unlock(k); 31 #else 32 struct k_thread *ret = _kernel.cpus[0].current; 33 #endif /* CONFIG_SMP */ 34 return ret; 35 } 36 arch_current_thread_set(struct k_thread * thread)37static ALWAYS_INLINE void arch_current_thread_set(struct k_thread *thread) 38 { 39 _current_cpu->current = thread; 40 } 41 #endif /* CONFIG_ARCH_HAS_CUSTOM_CURRENT_IMPL */ 42 43 #endif /* _ASMLANGUAGE */ 44 45 #endif /* ZEPHYR_INCLUDE_ZEPHYR_ARCH_COMMON_ARCH_INLINES_H_ */ 46