diff --git a/zion/scheduler/process.cpp b/zion/scheduler/process.cpp index 7d73ec0..fd1fae8 100644 --- a/zion/scheduler/process.cpp +++ b/zion/scheduler/process.cpp @@ -1,6 +1,7 @@ #include "scheduler/process.h" #include "debug/debug.h" +#include "scheduler/scheduler.h" #include "scheduler/thread.h" namespace { @@ -22,7 +23,7 @@ Process* Process::RootProcess() { return proc; } -Thread* Process::CreateThread() { +void Process::CreateThread() { Thread* thread = new Thread(this, next_thread_id_++); ThreadEntry* entry = thread_list_front_; @@ -33,7 +34,7 @@ Thread* Process::CreateThread() { .thread = thread, .next = nullptr, }; - return thread; + sched::EnqueueThread(thread); } Thread* Process::GetThread(uint64_t tid) { diff --git a/zion/scheduler/process.h b/zion/scheduler/process.h index 08308f5..503aecc 100644 --- a/zion/scheduler/process.h +++ b/zion/scheduler/process.h @@ -14,7 +14,7 @@ class Process { uint64_t id() { return id_; } uint64_t cr3() { return cr3_; } - Thread* CreateThread(); + void CreateThread(); Thread* GetThread(uint64_t tid); private: diff --git a/zion/scheduler/scheduler.cpp b/zion/scheduler/scheduler.cpp index 9337df8..614d653 100644 --- a/zion/scheduler/scheduler.cpp +++ b/zion/scheduler/scheduler.cpp @@ -49,8 +49,6 @@ class Scheduler { Process* root = Process::RootProcess(); current_thread_ = root->GetThread(0); proc_list_.InsertProcess(Process::RootProcess()); - // FIXME: Don't enqueue threads here. - Enqueue(root->CreateThread()); } void Enable() { enabled_ = true; } @@ -108,6 +106,8 @@ void EnableScheduler() { GetScheduler().Enable(); } void Yield() { GetScheduler().Yield(); } +void EnqueueThread(Thread* thread) { GetScheduler().Enqueue(thread); } + Process& CurrentProcess() { return GetScheduler().CurrentProcess(); } Thread& CurrentThread() { return GetScheduler().CurrentThread(); } diff --git a/zion/zion.cpp b/zion/zion.cpp index 040c17f..e961c82 100644 --- a/zion/zion.cpp +++ b/zion/zion.cpp @@ -18,6 +18,7 @@ extern "C" void zion() { phys_mem::InitPhysicalMemoryManager(); sched::InitScheduler(); + sched::CurrentProcess().CreateThread(); sched::EnableScheduler(); sched::Yield();