From 2868fd81220c82749a9a59c3fd3ea4abaa2b2c81 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 11 Dec 2024 19:16:45 +0100 Subject: [PATCH] kernel: Add a way to lookup specific threads --- kernel/src/thread/Scheduler.cpp | 10 ++++++++++ kernel/src/thread/Scheduler.h | 1 + 2 files changed, 11 insertions(+) diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 6d6d88db..35cb458d 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -409,6 +409,16 @@ namespace Scheduler return {}; } + Option find_by_tid(pid_t tid) + { + for (auto* const thread : g_threads) + { + if (thread->tid == tid) return thread; + } + + return {}; + } + bool has_children(Process* process) { bool result { false }; diff --git a/kernel/src/thread/Scheduler.h b/kernel/src/thread/Scheduler.h index a7244947..7021917a 100644 --- a/kernel/src/thread/Scheduler.h +++ b/kernel/src/thread/Scheduler.h @@ -38,6 +38,7 @@ namespace Scheduler LinkedList check_for_dead_processes(); Option find_by_pid(pid_t pid); + Option find_by_tid(pid_t tid); template void for_each_child(Process* process, Callback callback) {