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