Have processes enqueue their own threads

This commit is contained in:
Drew Galbraith 2023-05-18 13:28:22 -07:00
parent cb41953354
commit 0d275c72a1
4 changed files with 7 additions and 5 deletions

View File

@ -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) {

View File

@ -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:

View File

@ -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(); }

View File

@ -18,6 +18,7 @@ extern "C" void zion() {
phys_mem::InitPhysicalMemoryManager();
sched::InitScheduler();
sched::CurrentProcess().CreateThread();
sched::EnableScheduler();
sched::Yield();