scheduler + 2 instances of application
This commit is contained in:
8
main.cc
8
main.cc
@@ -71,10 +71,11 @@ OutputStream* copyout[Core::MAX]{
|
||||
|
||||
unsigned int testx, testy;
|
||||
|
||||
Context test1;
|
||||
uint8_t test1_stack[1024];
|
||||
uint8_t test2_stack[1024];
|
||||
//Thread test1_thread = Thread(&test1_stack[sizeof(test1_stack)-1]);
|
||||
Application application = Application(&test1_stack[sizeof(test1_stack)-1]);
|
||||
Application application1 = Application(&test1_stack[sizeof(test1_stack)-1]);
|
||||
Application application2 = Application(&test2_stack[sizeof(test2_stack)-1]);
|
||||
|
||||
//Context test2;
|
||||
//uint8_t test2_stack[256];
|
||||
@@ -127,7 +128,8 @@ extern "C" int main() {
|
||||
|
||||
DBG << "Main CPU " << static_cast<int>(LAPIC::getID()) << endl << flush;
|
||||
|
||||
sch.ready(&application);
|
||||
sch.ready(&application1);
|
||||
sch.ready(&application2);
|
||||
sch.schedule();
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "../../thread/scheduler.h"
|
||||
|
||||
extern Scheduler sch;
|
||||
static uint8_t appl_cnt = 0;
|
||||
|
||||
char text[] = "Ich mag\n\
|
||||
Saftige Pflaumen voller Aroma\n\
|
||||
@@ -40,13 +41,13 @@ void activeWaitDelay(uint64_t cycles) {
|
||||
|
||||
void Application::action() { // NOLINT
|
||||
uint16_t cnt = 0;
|
||||
uint8_t row = appl_cnt++;
|
||||
while (1) {
|
||||
//koutlock.lock();
|
||||
{
|
||||
Guarded g = Guard::enter();
|
||||
//g.vault();
|
||||
g.vault().kout.setPos((unsigned)0,(unsigned)Core::getID()*2+1);
|
||||
|
||||
g.vault().kout.setPos((unsigned)10*row,(unsigned)Core::getID()*2+1);
|
||||
g.vault().kout << cnt++ << flush;
|
||||
|
||||
//g.vault().kout << endl << flush;
|
||||
|
||||
Reference in New Issue
Block a user