#include "./semaphore.h" #include "../interrupt/guard.h" #include "../thread/scheduler.h" uint8_t counter; Queue waiting; Semaphore::Semaphore(unsigned c) { counter=c; } 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 waiting.enqueue(*vault.sch.active()); //was is der calling thread // } //release void Semaphore::v(Vault &vault) { Thread* first = waiting.dequeue(); if (first != nullptr) vault.sch.ready(first); //wakeup "first" thread else vault.counter++; }