diff --git a/main.cc b/main.cc index ea987ff..dc6f792 100644 --- a/main.cc +++ b/main.cc @@ -20,7 +20,7 @@ #include "arch/context.h" #include "thread/thread.h" -///TextStream kout = TextStream(0, 80, 0, 10, true); +TextStream kout = TextStream(0, 80, 0, 10, true); Ticketlock koutlock; //Scheduler sch; diff --git a/sync/semaphore.cc b/sync/semaphore.cc index 7ee3142..071b8b9 100644 --- a/sync/semaphore.cc +++ b/sync/semaphore.cc @@ -12,17 +12,18 @@ void Semaphore::p(Vault &vault) { //resource is frei, läuft direkt weiter if (vault.counter > 0) vault.counter--; - //else - /// thread block, zu aktueller queue hinzufügen und -// vault.sch.block(this); + else + //thread block, zu aktueller queue hinzufügen und + waiting.enqueue(*vault.sch.active()); //was is der calling thread + // } //release void Semaphore::v(Vault &vault) { - //Thread* first = waiting.dequeue(); - //if (first != nullptr) - // void Scheduler::wakeup(first); - //else + Thread* first = waiting.dequeue(); + if (first != nullptr) + vault.sch.ready(first); //wakeup "first" thread + else vault.counter++; } diff --git a/user/app1/appl.cc b/user/app1/appl.cc index 690bdb7..a04283e 100644 --- a/user/app1/appl.cc +++ b/user/app1/appl.cc @@ -9,9 +9,9 @@ #include "../../interrupt/guard.h" #include "../../debug/output.h" #include "../../arch/context.h" - +#include "../../sync/semaphore.h" static uint8_t appl_cnt = 0; - +extern TextStream kout; char text[] = "Ich mag\n\ Saftige Pflaumen voller Aroma\n\ Ich knuddel jede Oma ins Koma\n\ @@ -33,18 +33,21 @@ void activeWaitDelay(uint64_t cycles) { //Core::pause(); } } +Semaphore foo= Semaphore(1); void Application::action() { // NOLINT uint16_t cnt = 0; uint8_t row = appl_cnt++; while (1) { + Guarded g= Guard::enter(); + //koutlock.lock(); { - Guarded g = Guard::enter(); //g.vault(); - g.vault().kout.setPos((unsigned)8*row,(unsigned)/*Core::getID()*2+*/1); - g.vault().kout << cnt++ << flush; - + foo.p(g.vault()); + kout.setPos((unsigned)8*row,(unsigned)/*Core::getID()*2+*/1); + kout << cnt++ << flush; + foo.v(g.vault()); //g.vault().kout << endl << flush; //Guard::leave(); //koutlock.unlock();