Cycle through multiple tasks in multiple processes
This commit is contained in:
parent
7a3b4d2d42
commit
d3024211a7
6 changed files with 56 additions and 12 deletions
|
|
@ -1,6 +1,8 @@
|
|||
#include "scheduler/process.h"
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "memory/physical_memory.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
#include "scheduler/thread.h"
|
||||
|
||||
|
|
@ -23,17 +25,28 @@ Process* Process::RootProcess() {
|
|||
return proc;
|
||||
}
|
||||
|
||||
Process::Process() : id_(gNextId++) {
|
||||
cr3_ = phys_mem::AllocatePage();
|
||||
InitializePml4(cr3_);
|
||||
CreateThread();
|
||||
}
|
||||
|
||||
void Process::CreateThread() {
|
||||
Thread* thread = new Thread(this, next_thread_id_++);
|
||||
|
||||
ThreadEntry* entry = thread_list_front_;
|
||||
while (entry->next != nullptr) {
|
||||
entry = entry->next;
|
||||
}
|
||||
entry->next = new ThreadEntry{
|
||||
ThreadEntry* tentry = new ThreadEntry{
|
||||
.thread = thread,
|
||||
.next = nullptr,
|
||||
};
|
||||
|
||||
if (thread_list_front_ == nullptr) {
|
||||
thread_list_front_ = tentry;
|
||||
} else {
|
||||
ThreadEntry* entry = thread_list_front_;
|
||||
while (entry->next != nullptr) {
|
||||
entry = entry->next;
|
||||
}
|
||||
entry->next = tentry;
|
||||
}
|
||||
sched::EnqueueThread(thread);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ class Scheduler {
|
|||
Thread* prev = current_thread_;
|
||||
current_thread_ = current_thread_->next_thread_;
|
||||
prev->next_thread_ = nullptr;
|
||||
Enqueue(prev);
|
||||
if (prev->pid() != 0) {
|
||||
Enqueue(prev);
|
||||
}
|
||||
context_switch(prev->Rsp0Ptr(), current_thread_->Rsp0Ptr());
|
||||
|
||||
asm volatile("sti");
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ namespace {
|
|||
|
||||
extern "C" void thread_init() {
|
||||
asm("sti");
|
||||
dbgln("New Thread!");
|
||||
sched::Yield();
|
||||
panic("End of thread.");
|
||||
sched::CurrentThread().Init();
|
||||
panic("Reached end of thread.");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -32,3 +31,10 @@ Thread::Thread(Process* proc, uint64_t tid) : process_(proc), id_(tid) {
|
|||
}
|
||||
|
||||
uint64_t Thread::pid() { return process_->id(); }
|
||||
|
||||
void Thread::Init() {
|
||||
while (true) {
|
||||
dbgln("[%u.%u]", pid(), id_);
|
||||
sched::Yield();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ class Thread {
|
|||
|
||||
uint64_t* Rsp0Ptr() { return &rsp0_; }
|
||||
|
||||
// Called the first time the thread starts up.
|
||||
void Init();
|
||||
|
||||
// FIXME: Probably make this private.
|
||||
Thread* next_thread_;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue