From 59a682c72037f8b2983ad553682158f4a35d666c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 19 Apr 2023 00:39:06 +0300 Subject: [PATCH] Kernel: init2 is now launched as a process instead of thread Also only process can now add threads to scheduler. Nobody should have raw access to scheduler and everything should be through Process::current() or irqs (reschedules) --- kernel/include/kernel/Scheduler.h | 6 ++++-- kernel/kernel/kernel.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/include/kernel/Scheduler.h b/kernel/include/kernel/Scheduler.h index 278245a0..56a24263 100644 --- a/kernel/include/kernel/Scheduler.h +++ b/kernel/include/kernel/Scheduler.h @@ -17,8 +17,6 @@ namespace Kernel void reschedule(); void reschedule_if_idling(); - BAN::ErrorOr add_thread(Thread*); - void set_current_thread_sleeping(uint64_t); [[noreturn]] void set_current_thread_done(); @@ -38,6 +36,8 @@ namespace Kernel void advance_current_thread(); [[noreturn]] void execute_current_thread(); + BAN::ErrorOr add_thread(Thread*); + private: struct ActiveThread { @@ -69,6 +69,8 @@ namespace Kernel BAN::LinkedList::iterator m_current_thread; uint64_t m_last_reschedule = 0; + + friend class Process; }; } \ No newline at end of file diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index ca47face..02e52acb 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -165,9 +165,9 @@ extern "C" void kernel_main() MUST(Scheduler::initialize()); Scheduler& scheduler = Scheduler::get(); - MUST(scheduler.add_thread(MUST(Thread::create(init2, tty1, nullptr)))); + MUST(Process::create_kernel(init2, tty1)); scheduler.start(); - + ASSERT_NOT_REACHED(); }