scheduler + 2 instances of application

main
Eggert Jung 4 months ago
parent da34f7cada
commit e6d6e7521c

@ -71,10 +71,11 @@ OutputStream* copyout[Core::MAX]{
unsigned int testx, testy; unsigned int testx, testy;
Context test1;
uint8_t test1_stack[1024]; uint8_t test1_stack[1024];
uint8_t test2_stack[1024];
//Thread test1_thread = Thread(&test1_stack[sizeof(test1_stack)-1]); //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; //Context test2;
//uint8_t test2_stack[256]; //uint8_t test2_stack[256];
@ -127,7 +128,8 @@ extern "C" int main() {
DBG << "Main CPU " << static_cast<int>(LAPIC::getID()) << endl << flush; DBG << "Main CPU " << static_cast<int>(LAPIC::getID()) << endl << flush;
sch.ready(&application); sch.ready(&application1);
sch.ready(&application2);
sch.schedule(); sch.schedule();

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

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

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

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

@ -1,6 +1,7 @@
// vim: set noet ts=4 sw=4: // vim: set noet ts=4 sw=4:
#include "thread.h" #include "thread.h"
#include "../debug/output.h"
#include "../arch/context.h" #include "../arch/context.h"
// Alias to simplify stuff // Alias to simplify stuff
@ -14,8 +15,16 @@ Thread::Thread(void* tos) {
prepareContext(tos, context, (void(*)(void*)) &(kickoff), this); prepareContext(tos, context, (void(*)(void*)) &(kickoff), this);
} }
#include "../thread/scheduler.h"
extern Scheduler sch;
void Thread::resume(Thread* next) { 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() { void Thread::go() {

@ -12,6 +12,7 @@
#include "../../thread/scheduler.h" #include "../../thread/scheduler.h"
extern Scheduler sch; extern Scheduler sch;
static uint8_t appl_cnt = 0;
char text[] = "Ich mag\n\ char text[] = "Ich mag\n\
Saftige Pflaumen voller Aroma\n\ Saftige Pflaumen voller Aroma\n\
@ -40,13 +41,13 @@ void activeWaitDelay(uint64_t cycles) {
void Application::action() { // NOLINT void Application::action() { // NOLINT
uint16_t cnt = 0; uint16_t cnt = 0;
uint8_t row = appl_cnt++;
while (1) { while (1) {
//koutlock.lock(); //koutlock.lock();
{ {
Guarded g = Guard::enter(); Guarded g = Guard::enter();
//g.vault(); //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 << cnt++ << flush;
//g.vault().kout << endl << flush; //g.vault().kout << endl << flush;

Loading…
Cancel
Save