diff --git a/kernel/thread.c b/kernel/thread.c index b0d11e7ff9a..a5cebe3a3ed 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -55,9 +55,15 @@ void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data) * k_thread_abort from user_cb. */ key = k_spin_lock(&z_thread_monitor_lock); + + _FOREACH_STATIC_THREAD(thread_data) { + user_cb(thread_data->init_thread, user_data); + } + for (thread = _kernel.threads; thread; thread = thread->next_thread) { user_cb(thread, user_data); } + k_spin_unlock(&z_thread_monitor_lock, key); #endif } @@ -71,11 +77,19 @@ void k_thread_foreach_unlocked(k_thread_user_cb_t user_cb, void *user_data) __ASSERT(user_cb != NULL, "user_cb can not be NULL"); key = k_spin_lock(&z_thread_monitor_lock); + + _FOREACH_STATIC_THREAD(thread_data) { + k_spin_unlock(&z_thread_monitor_lock, key); + user_cb(thread_data->init_thread, user_data); + key = k_spin_lock(&z_thread_monitor_lock); + } + for (thread = _kernel.threads; thread; thread = thread->next_thread) { k_spin_unlock(&z_thread_monitor_lock, key); user_cb(thread, user_data); key = k_spin_lock(&z_thread_monitor_lock); } + k_spin_unlock(&z_thread_monitor_lock, key); #endif }