scheduler + 2 instances of application

This commit is contained in:
Eggert Jung
2025-06-23 20:21:19 +02:00
parent da34f7cada
commit e6d6e7521c
7 changed files with 28 additions and 15 deletions

View File

@@ -27,6 +27,6 @@ void Dispatcher::go(Thread *first) {
}
void Dispatcher::dispatch(Thread *next) {
lifePointer[Core::getID()] = next;
//lifePointer[Core::getID()] = next;
lifePointer[Core::getID()]->resume(next);
}

View File

@@ -24,7 +24,6 @@ class Dispatcher {
*/
void setActive(Thread* thread) { (void)thread; }
Thread* lifePointer[Core::MAX];
public:
/*! \brief constructor
@@ -32,6 +31,7 @@ class Dispatcher {
* \todo(14) Implement Method
*/
Dispatcher();
Thread* lifePointer[Core::MAX];
/*! \brief Returns the thread currently running on the CPU core calling
* this method

View File

@@ -22,8 +22,8 @@ void Scheduler::ready(Thread* that) {
}
void Scheduler::resume(bool ready) {
if (ready)
//if (!active()->kill_flag)
if (ready)
readyList.enqueue(*active());
Thread* thread = readyList.dequeue();
assert(thread != nullptr);

View File

@@ -22,12 +22,7 @@
* taken from the front of the queue.
*/
class Scheduler {
/*! \brief a Dispatcher object, providing the low level context switching
* routines.
*/
Dispatcher dispatcher;
/*! \brief Helper to retrieve next Thread
/*! \brief Helper to retrieve next Thread
* \return pointer of next thread
*/
Thread* getNext();
@@ -36,6 +31,12 @@ class Scheduler {
public:
Scheduler();
/*! \brief a Dispatcher object, providing the low level context switching
* routines.
*/
Dispatcher dispatcher;
/*! \brief Start scheduling
*
* This method starts the scheduling by removing the first thread from

View File

@@ -1,6 +1,7 @@
// vim: set noet ts=4 sw=4:
#include "thread.h"
#include "../debug/output.h"
#include "../arch/context.h"
// Alias to simplify stuff
@@ -14,8 +15,16 @@ Thread::Thread(void* tos) {
prepareContext(tos, context, (void(*)(void*)) &(kickoff), this);
}
#include "../thread/scheduler.h"
extern Scheduler sch;
void Thread::resume(Thread* next) {
context_switch(&next->context, &context);
Context *from = &sch.active()->context;
Context *to = &next->context;
sch.dispatcher.lifePointer[Core::getID()] = next;
DBG << "from: " << hex << from << endl;
DBG << "to : " << hex << to << endl << flush;
context_switch(to, from);
}
void Thread::go() {