diff --git a/kernel/src/sys/exit.cpp b/kernel/src/sys/exit.cpp index ee49c84e..1b005e5b 100644 --- a/kernel/src/sys/exit.cpp +++ b/kernel/src/sys/exit.cpp @@ -7,7 +7,7 @@ Result sys_exit(Registers*, SyscallArgs args) Thread* current = Scheduler::current(); - Scheduler::for_each_child((pid_t)current->id, [](Thread* child) { + Scheduler::for_each_child(current, [](Thread* child) { child->parent_id = 1; return true; }); diff --git a/kernel/src/sys/waitpid.cpp b/kernel/src/sys/waitpid.cpp index 698cfc6f..ce069d6d 100644 --- a/kernel/src/sys/waitpid.cpp +++ b/kernel/src/sys/waitpid.cpp @@ -27,11 +27,11 @@ Result sys_waitpid(Registers*, SyscallArgs args) } else if (pid == -1) { - if (!Scheduler::has_children((pid_t)current->id)) return err(ECHILD); + if (!Scheduler::has_children(current)) return err(ECHILD); Option child; - while (child = Scheduler::find_exited_child((pid_t)current->id), !child.has_value()) + while (child = Scheduler::find_exited_child(current), !child.has_value()) { if (options & WNOHANG) return err(EAGAIN); kernel_sleep(10); diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index c16c2561..96c41356 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -285,11 +285,11 @@ namespace Scheduler return {}; } - bool has_children(pid_t pid) + bool has_children(Thread* thread) { bool result { false }; - for_each_child(pid, [&](Thread*) { + for_each_child(thread, [&](Thread*) { result = true; return false; }); @@ -297,11 +297,11 @@ namespace Scheduler return result; } - Option find_exited_child(pid_t pid) + Option find_exited_child(Thread* thread) { Option result; - for_each_child(pid, [&](Thread* child) { + for_each_child(thread, [&](Thread* child) { if (!result.has_value() && child->state == ThreadState::Exited) { result = child; diff --git a/kernel/src/thread/Scheduler.h b/kernel/src/thread/Scheduler.h index 3e1f07fe..122baa3b 100644 --- a/kernel/src/thread/Scheduler.h +++ b/kernel/src/thread/Scheduler.h @@ -29,21 +29,21 @@ namespace Scheduler Option find_by_pid(pid_t pid); - template void for_each_child(pid_t pid, Callback callback) + template void for_each_child(Thread* thread, Callback callback) { - for (auto* const thread : g_threads) + for (Thread* current = thread; current; current = g_threads.next(current).value_or(nullptr)) { - if (thread->parent_id == (u64)pid) + if (current && current->parent_id == thread->id) { - bool should_continue = callback(thread); + bool should_continue = callback(current); if (!should_continue) return; } } } - bool has_children(pid_t pid); + bool has_children(Thread* thread); - Option find_exited_child(pid_t pid); + Option find_exited_child(Thread* thread); } extern "C" void kernel_yield();