From 5b664840d88f4fe2001bd3782d28a0cfdd34c602 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Tue, 17 Jun 2025 15:41:56 +0200 Subject: [PATCH] progress on scheduler/dispatcher implementation --- thread/dispatcher.cc | 27 ++++++++++++++++++++------- thread/dispatcher.h | 3 +++ thread/scheduler.cc | 36 ++++++++++++++++++++++++++++++------ thread/scheduler.h | 1 + 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/thread/dispatcher.cc b/thread/dispatcher.cc index 5044a50..6ffb6cc 100644 --- a/thread/dispatcher.cc +++ b/thread/dispatcher.cc @@ -1,17 +1,30 @@ // vim: set noet ts=4 sw=4: #include "dispatcher.h" +#include "core.h" -Dispatcher::Dispatcher() {} +Dispatcher::Dispatcher() { +} -Thread *Dispatcher::active() { return nullptr; } +Thread *Dispatcher::active() { + return lifePointer[Core::getID()]; +} bool Dispatcher::isActive(const Thread *thread, unsigned *cpu) { - (void)thread; - (void)cpu; - return false; + for(uint8_t i=0; igo(); +} -void Dispatcher::dispatch(Thread *next) { (void)next; } +void Dispatcher::dispatch(Thread *next) { + lifePointer[Core::getID()]->resume(next); +} diff --git a/thread/dispatcher.h b/thread/dispatcher.h index 481740e..d52c83b 100644 --- a/thread/dispatcher.h +++ b/thread/dispatcher.h @@ -6,6 +6,7 @@ #pragma once #include "../thread/thread.h" #include "../types.h" +#include "core.h" /*! \brief The dispatcher dispatches threads and puts the scheduler's * decisions into action. @@ -23,6 +24,8 @@ class Dispatcher { */ void setActive(Thread* thread) { (void)thread; } + Thread* lifePointer[Core::MAX]; + public: /*! \brief constructor * diff --git a/thread/scheduler.cc b/thread/scheduler.cc index 8a6f78c..405e8e4 100644 --- a/thread/scheduler.cc +++ b/thread/scheduler.cc @@ -2,19 +2,43 @@ #include "scheduler.h" -Scheduler::Scheduler() {} +Queue readyList = Queue(0); + +Scheduler::Scheduler() { +} Thread* Scheduler::getNext() { return nullptr; } -void Scheduler::schedule() {} +void Scheduler::schedule() { + // TODO maybe guard? + Thread* next = readyList.dequeue(); + assert(next != nullptr); + dispatcher.go(next); +} -void Scheduler::ready(Thread* that) { (void)that; } +void Scheduler::ready(Thread* that) { + assert(that != nullptr); + readyList.enqueue(*that); +} -void Scheduler::resume(bool ready) { (void)ready; } +void Scheduler::resume(bool ready) { + if (!active()->kill_flag) + readyList.enqueue(*active()); + Thread* thread = readyList.dequeue(); + assert(thread != nullptr); + dispatcher.dispatch(thread); +} -void Scheduler::exit() {} +void Scheduler::exit() { + Thread* thread = readyList.dequeue(); + assert(thread != nullptr); + dispatcher.dispatch(thread); +} -void Scheduler::kill(Thread* that) { (void)that; } +void Scheduler::kill(Thread* that) { + readyList.remove(that); + that->kill_flag = true; +} bool Scheduler::isActive(const Thread* that, unsigned int* cpu) { (void)that; diff --git a/thread/scheduler.h b/thread/scheduler.h index ece07bc..ce880a0 100644 --- a/thread/scheduler.h +++ b/thread/scheduler.h @@ -32,6 +32,7 @@ class Scheduler { */ Thread* getNext(); + public: Scheduler();