progress on scheduler/dispatcher implementation
This commit is contained in:
@@ -1,17 +1,30 @@
|
||||
// vim: set noet ts=4 sw=4:
|
||||
|
||||
#include "dispatcher.h"
|
||||
#include "core.h"
|
||||
|
||||
Dispatcher::Dispatcher() {}
|
||||
|
||||
Thread *Dispatcher::active() { return nullptr; }
|
||||
|
||||
bool Dispatcher::isActive(const Thread *thread, unsigned *cpu) {
|
||||
(void)thread;
|
||||
(void)cpu;
|
||||
return false;
|
||||
Dispatcher::Dispatcher() {
|
||||
}
|
||||
|
||||
void Dispatcher::go(Thread *first) { (void)first; }
|
||||
Thread *Dispatcher::active() {
|
||||
return lifePointer[Core::getID()];
|
||||
}
|
||||
|
||||
void Dispatcher::dispatch(Thread *next) { (void)next; }
|
||||
bool Dispatcher::isActive(const Thread *thread, unsigned *cpu) {
|
||||
for(uint8_t i=0; i<Core::MAX; i++){
|
||||
if(thread == lifePointer[i]){
|
||||
*cpu = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
cpu = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Dispatcher::go(Thread *first) {
|
||||
first->go();
|
||||
}
|
||||
|
||||
void Dispatcher::dispatch(Thread *next) {
|
||||
lifePointer[Core::getID()]->resume(next);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -2,19 +2,43 @@
|
||||
|
||||
#include "scheduler.h"
|
||||
|
||||
Scheduler::Scheduler() {}
|
||||
Queue<Thread> readyList = Queue<Thread>(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;
|
||||
|
||||
@@ -32,6 +32,7 @@ class Scheduler {
|
||||
*/
|
||||
Thread* getNext();
|
||||
|
||||
|
||||
public:
|
||||
Scheduler();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user