kernel: make k_current_get() work without syscall
We cache the current thread ID in a thread-local variable at thread entry, and have k_current_get() return that, eliminating system call overhead for this API. DL: changed _current to use z_current_get() as it is being used during boot where TLS is not available. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com> Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
c661765f1d
commit
f07df42d49
4 changed files with 35 additions and 6 deletions
|
@ -487,13 +487,35 @@ __syscall void k_yield(void);
|
|||
*/
|
||||
__syscall void k_wakeup(k_tid_t thread);
|
||||
|
||||
/**
|
||||
* @brief Get thread ID of the current thread.
|
||||
*
|
||||
* This unconditionally queries the kernel via a system call.
|
||||
*
|
||||
* @return ID of current thread.
|
||||
*/
|
||||
__syscall k_tid_t z_current_get(void);
|
||||
|
||||
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||
/* Thread-local cache of current thread ID, set in z_thread_entry() */
|
||||
extern __thread k_tid_t z_tls_current;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get thread ID of the current thread.
|
||||
*
|
||||
* @return ID of current thread.
|
||||
*
|
||||
*/
|
||||
__syscall k_tid_t k_current_get(void) __attribute_const__;
|
||||
__attribute_const__
|
||||
static inline k_tid_t k_current_get(void)
|
||||
{
|
||||
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||
return z_tls_current;
|
||||
#else
|
||||
return z_current_get();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Abort a thread.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue