[zion] Move the scheduler to the IntrusiveList for runnable threads

This commit is contained in:
Drew Galbraith 2023-06-21 16:28:42 -07:00
parent 25737d9377
commit a99096b0ff
3 changed files with 6 additions and 5 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <glacier/container/intrusive_list.h>
#include <glacier/memory/ref_ptr.h>
#include <stdint.h>
@ -14,7 +15,7 @@ struct KernelObjectTag<Thread> {
static const uint64_t type = KernelObject::THREAD;
};
class Thread : public KernelObject {
class Thread : public KernelObject, public glcr::IntrusiveListNode<Thread> {
public:
uint64_t TypeTag() override { return KernelObject::THREAD; }
enum State {

View File

@ -61,7 +61,8 @@ void Scheduler::Preempt() {
glcr::RefPtr<Thread> prev = current_thread_;
prev->SetState(Thread::RUNNABLE);
current_thread_ = runnable_threads_.CycleFront(prev);
runnable_threads_.PushBack(prev);
current_thread_ = runnable_threads_.PopFront();
SwapToCurrent(*prev);
}
@ -79,7 +80,6 @@ void Scheduler::Yield() {
panic("Sleep thread yielded without next.");
return;
} else {
// FIXME: Memory operation.
current_thread_ = runnable_threads_.PopFront();
prev->SetState(Thread::RUNNABLE);
}
@ -89,7 +89,6 @@ void Scheduler::Yield() {
dbgln("Sleeping");
gProcMan->DumpProcessStates();
} else {
// FIXME: Memory operation.
current_thread_ = runnable_threads_.PopFront();
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <glacier/container/intrusive_list.h>
#include <glacier/memory/ref_ptr.h>
#include "object/process.h"
@ -28,7 +29,7 @@ class Scheduler {
bool enabled_ = false;
glcr::RefPtr<Thread> current_thread_;
LinkedList<glcr::RefPtr<Thread>> runnable_threads_;
glcr::IntrusiveList<Thread> runnable_threads_;
glcr::RefPtr<Thread> sleep_thread_;