kernel_structs: Add macro CPU_ID for getting current CPU ID

In case of a single core it resolves to 0. In many cases it reduces
code size and execution time compared to reading id in runtime.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2025-04-04 13:47:00 +02:00 committed by Benjamin Cabé
commit 49337973e0

View file

@ -257,6 +257,8 @@ __attribute_const__ struct k_thread *z_smp_current_get(void);
#define _current _kernel.cpus[0].current #define _current _kernel.cpus[0].current
#endif #endif
#define CPU_ID ((CONFIG_MP_MAX_NUM_CPUS == 1) ? 0 : _current_cpu->id)
/* This is always invoked from a context where preemption is disabled */ /* This is always invoked from a context where preemption is disabled */
#define z_current_thread_set(thread) ({ _current_cpu->current = (thread); }) #define z_current_thread_set(thread) ({ _current_cpu->current = (thread); })