kernel/sched: Optimize handling for suspend(_current)
k_thread_suspend() is an async API intended to stop any thread in any state from any context. Some apps just want to use it to "suspend myself", which is a much (!) simpler operation. Detect that specific usage as a performance case. Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
parent
22de29e768
commit
b3ff9ae82b
1 changed files with 13 additions and 0 deletions
|
@ -499,6 +499,19 @@ void z_impl_k_thread_suspend(k_tid_t thread)
|
|||
{
|
||||
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_thread, suspend, thread);
|
||||
|
||||
/* Special case "suspend the current thread" as it doesn't
|
||||
* need the async complexity below.
|
||||
*/
|
||||
if (thread == _current && !arch_is_in_isr() && !IS_ENABLED(CONFIG_SMP)) {
|
||||
k_spinlock_key_t key = k_spin_lock(&_sched_spinlock);
|
||||
|
||||
z_mark_thread_as_suspended(thread);
|
||||
dequeue_thread(thread);
|
||||
update_cache(1);
|
||||
z_swap(&_sched_spinlock, key);
|
||||
return;
|
||||
}
|
||||
|
||||
(void)z_abort_thread_timeout(thread);
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&_sched_spinlock);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue