progress on scheduler/dispatcher implementation
This commit is contained in:
@@ -1,17 +1,30 @@
|
|||||||
// vim: set noet ts=4 sw=4:
|
// vim: set noet ts=4 sw=4:
|
||||||
|
|
||||||
#include "dispatcher.h"
|
#include "dispatcher.h"
|
||||||
|
#include "core.h"
|
||||||
|
|
||||||
Dispatcher::Dispatcher() {}
|
Dispatcher::Dispatcher() {
|
||||||
|
|
||||||
Thread *Dispatcher::active() { return nullptr; }
|
|
||||||
|
|
||||||
bool Dispatcher::isActive(const Thread *thread, unsigned *cpu) {
|
|
||||||
(void)thread;
|
|
||||||
(void)cpu;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
#pragma once
|
||||||
#include "../thread/thread.h"
|
#include "../thread/thread.h"
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
|
#include "core.h"
|
||||||
|
|
||||||
/*! \brief The dispatcher dispatches threads and puts the scheduler's
|
/*! \brief The dispatcher dispatches threads and puts the scheduler's
|
||||||
* decisions into action.
|
* decisions into action.
|
||||||
@@ -23,6 +24,8 @@ class Dispatcher {
|
|||||||
*/
|
*/
|
||||||
void setActive(Thread* thread) { (void)thread; }
|
void setActive(Thread* thread) { (void)thread; }
|
||||||
|
|
||||||
|
Thread* lifePointer[Core::MAX];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! \brief constructor
|
/*! \brief constructor
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,19 +2,43 @@
|
|||||||
|
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
|
||||||
Scheduler::Scheduler() {}
|
Queue<Thread> readyList = Queue<Thread>(0);
|
||||||
|
|
||||||
|
Scheduler::Scheduler() {
|
||||||
|
}
|
||||||
|
|
||||||
Thread* Scheduler::getNext() { return nullptr; }
|
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) {
|
bool Scheduler::isActive(const Thread* that, unsigned int* cpu) {
|
||||||
(void)that;
|
(void)that;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class Scheduler {
|
|||||||
*/
|
*/
|
||||||
Thread* getNext();
|
Thread* getNext();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Scheduler();
|
Scheduler();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user