hopefully added semaphores
This commit is contained in:
2
main.cc
2
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;
|
||||
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user