k_current_get(): make it a "const" function

This function always returns the same value for a given thread.
Add the const attribute to it so the compiler won't call it over and
over needlessly each time _current is referenced, making for far more
efficient code.

The __attribute_const__ symbol is used to mimic the Linux equivalent.
We want to make it clear that this is distinct from the const keyword.

Fix the test_x86_cpu_scrubs_regs where the compiler wasn't told that a
bunch of registers are being clobbered as highlighted by this change.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2021-04-09 00:40:41 -04:00 committed by Anas Nashif
commit 0dc7b9ee46
4 changed files with 22 additions and 15 deletions

View file

@ -528,7 +528,7 @@ __syscall void k_wakeup(k_tid_t thread);
* @return ID of current thread.
*
*/
__syscall k_tid_t k_current_get(void);
__syscall k_tid_t k_current_get(void) __attribute_const__;
/**
* @brief Abort a thread.