zephyr/subsys/shell/modules/kernel_service/thread/thread.c
Yong Cong Sin aa9446ca6b shell: modules: kernel: cleanup thread list subcmd
Parts related to the thread runtime stats are somewhat
standalone, refactor it out instead of having two #ifdef
and two places.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-17 20:12:33 -04:00

42 lines
834 B
C

/*
* Copyright (c) 2024 Meta Platforms
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "kernel_shell.h"
#include <kernel_internal.h>
#include <zephyr/drivers/timer/system_timer.h>
#include <zephyr/debug/symtab.h>
#include <zephyr/kernel.h>
struct thread_entry {
const struct k_thread *const thread;
bool valid;
};
static void thread_valid_cb(const struct k_thread *cthread, void *user_data)
{
struct thread_entry *entry = user_data;
if (cthread == entry->thread) {
entry->valid = true;
}
}
bool z_thread_is_valid(const struct k_thread *thread)
{
struct thread_entry entry = {
.thread = thread,
.valid = false,
};
k_thread_foreach(thread_valid_cb, &entry);
return entry.valid;
}
SHELL_SUBCMD_SET_CREATE(sub_kernel_thread, (thread));
KERNEL_CMD_ADD(thread, &sub_kernel_thread, "Kernel threads.", NULL);