Skip to content

Commit c33c111

Browse files
Nicolas Pitreanangl
Nicolas Pitre
authored andcommitted
[nrf fromtree] kernel: mark z_smp_current_get() with the const attribute
Repeated references to _current won't produce a different result as the executing thread instance is always the same. Use the const attribute to let the compiler know it may reuse a previously obtained value. This offset the penalty for moving z_smp_current_get() out of line and provides yet more binary size reduction. This change is isolated in its own commit to ease bisecting in case some unexpected misbehavior is eventually observed. Signed-off-by: Nicolas Pitre <npitre@baylibre.com> (cherry picked from commit bc6eded)
1 parent d461596 commit c33c111

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/zephyr/kernel_structs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ bool z_smp_cpu_mobile(void);
263263
#define _current_cpu ({ __ASSERT_NO_MSG(!z_smp_cpu_mobile()); \
264264
arch_curr_cpu(); })
265265

266-
struct k_thread *z_smp_current_get(void);
266+
__attribute_const__ struct k_thread *z_smp_current_get(void);
267267
#define _current z_smp_current_get()
268268

269269
#else

kernel/smp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ bool z_smp_cpu_mobile(void)
249249
return !pinned;
250250
}
251251

252-
struct k_thread *z_smp_current_get(void)
252+
__attribute_const__ struct k_thread *z_smp_current_get(void)
253253
{
254254
/*
255255
* _current is a field read from _current_cpu, which can race

0 commit comments

Comments
 (0)