Skip to content

Commit 4933797

Browse files
nordic-krchkartben
authored andcommitted
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>
1 parent aa34fa8 commit 4933797

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

include/zephyr/kernel_structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ __attribute_const__ struct k_thread *z_smp_current_get(void);
257257
#define _current _kernel.cpus[0].current
258258
#endif
259259

260+
#define CPU_ID ((CONFIG_MP_MAX_NUM_CPUS == 1) ? 0 : _current_cpu->id)
261+
260262
/* This is always invoked from a context where preemption is disabled */
261263
#define z_current_thread_set(thread) ({ _current_cpu->current = (thread); })
262264

0 commit comments

Comments
 (0)