You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
584 B
C++
30 lines
584 B
C++
#include "./semaphore.h"
|
|
#include "../interrupt/guard.h"
|
|
#include "../thread/scheduler.h"
|
|
uint8_t counter;
|
|
Queue<Thread> 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
|
|
// vault.sch.block(this);
|
|
}
|
|
|
|
//release
|
|
void Semaphore::v(Vault &vault) {
|
|
//Thread* first = waiting.dequeue();
|
|
//if (first != nullptr)
|
|
// void Scheduler::wakeup(first);
|
|
//else
|
|
vault.counter++;
|
|
}
|
|
|
|
|