Have processes enqueue their own threads
This commit is contained in:
parent
cb41953354
commit
0d275c72a1
|
@ -1,6 +1,7 @@
|
||||||
#include "scheduler/process.h"
|
#include "scheduler/process.h"
|
||||||
|
|
||||||
#include "debug/debug.h"
|
#include "debug/debug.h"
|
||||||
|
#include "scheduler/scheduler.h"
|
||||||
#include "scheduler/thread.h"
|
#include "scheduler/thread.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -22,7 +23,7 @@ Process* Process::RootProcess() {
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread* Process::CreateThread() {
|
void Process::CreateThread() {
|
||||||
Thread* thread = new Thread(this, next_thread_id_++);
|
Thread* thread = new Thread(this, next_thread_id_++);
|
||||||
|
|
||||||
ThreadEntry* entry = thread_list_front_;
|
ThreadEntry* entry = thread_list_front_;
|
||||||
|
@ -33,7 +34,7 @@ Thread* Process::CreateThread() {
|
||||||
.thread = thread,
|
.thread = thread,
|
||||||
.next = nullptr,
|
.next = nullptr,
|
||||||
};
|
};
|
||||||
return thread;
|
sched::EnqueueThread(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread* Process::GetThread(uint64_t tid) {
|
Thread* Process::GetThread(uint64_t tid) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Process {
|
||||||
uint64_t id() { return id_; }
|
uint64_t id() { return id_; }
|
||||||
uint64_t cr3() { return cr3_; }
|
uint64_t cr3() { return cr3_; }
|
||||||
|
|
||||||
Thread* CreateThread();
|
void CreateThread();
|
||||||
Thread* GetThread(uint64_t tid);
|
Thread* GetThread(uint64_t tid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -49,8 +49,6 @@ class Scheduler {
|
||||||
Process* root = Process::RootProcess();
|
Process* root = Process::RootProcess();
|
||||||
current_thread_ = root->GetThread(0);
|
current_thread_ = root->GetThread(0);
|
||||||
proc_list_.InsertProcess(Process::RootProcess());
|
proc_list_.InsertProcess(Process::RootProcess());
|
||||||
// FIXME: Don't enqueue threads here.
|
|
||||||
Enqueue(root->CreateThread());
|
|
||||||
}
|
}
|
||||||
void Enable() { enabled_ = true; }
|
void Enable() { enabled_ = true; }
|
||||||
|
|
||||||
|
@ -108,6 +106,8 @@ void EnableScheduler() { GetScheduler().Enable(); }
|
||||||
|
|
||||||
void Yield() { GetScheduler().Yield(); }
|
void Yield() { GetScheduler().Yield(); }
|
||||||
|
|
||||||
|
void EnqueueThread(Thread* thread) { GetScheduler().Enqueue(thread); }
|
||||||
|
|
||||||
Process& CurrentProcess() { return GetScheduler().CurrentProcess(); }
|
Process& CurrentProcess() { return GetScheduler().CurrentProcess(); }
|
||||||
Thread& CurrentThread() { return GetScheduler().CurrentThread(); }
|
Thread& CurrentThread() { return GetScheduler().CurrentThread(); }
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ extern "C" void zion() {
|
||||||
phys_mem::InitPhysicalMemoryManager();
|
phys_mem::InitPhysicalMemoryManager();
|
||||||
|
|
||||||
sched::InitScheduler();
|
sched::InitScheduler();
|
||||||
|
sched::CurrentProcess().CreateThread();
|
||||||
sched::EnableScheduler();
|
sched::EnableScheduler();
|
||||||
sched::Yield();
|
sched::Yield();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue