Compare commits
No commits in common. '6951311c9c533ad5e86383278ca9b166ac9ed5b1' and '9ffd22e9412d8f8a3637fda6c42f59e4f31cea9c' have entirely different histories.
6951311c9c
...
9ffd22e941
@ -1,38 +1,16 @@
|
||||
#include "./bellringer.h"
|
||||
|
||||
#include "../interrupt/guard.h"
|
||||
|
||||
// check: Checks whether bells are running out of time and rings them if
|
||||
// necessary
|
||||
void Bellringer::check(Vault &vault) {
|
||||
auto first = vault.bellringer.bells.dequeue();
|
||||
first->counter--;
|
||||
if (vault.bellringer.bellPending()){
|
||||
vault.bellringer.bells.insertFirst(*first);
|
||||
}
|
||||
if (vault.bellringer.bellPending()){
|
||||
if (first->counter < 1) {
|
||||
vault.sch.ready(vault.bellringer.bells.dequeue()->thread);
|
||||
}
|
||||
void Bellringer::check(Vault &vault) { (void)vault; }
|
||||
|
||||
}
|
||||
}
|
||||
// job: Give a bell to the bellringer & ring it when the specified time ran out.
|
||||
void Bellringer::sleep(Vault &vault, unsigned int ms) {
|
||||
Bell bell;
|
||||
bell.thread = vault.sch.dispatcher.active();
|
||||
auto tmp = vault.bellringer.bells.dequeue();
|
||||
vault.bellringer.bells.insertFirst(*tmp);
|
||||
do{
|
||||
ms-=tmp->counter;
|
||||
} while ((tmp=vault.bellringer.bells.next(*tmp)) != nullptr );
|
||||
bell.counter = ms;
|
||||
vault.sch.resume(false);
|
||||
(void)vault;
|
||||
(void)ms;
|
||||
}
|
||||
|
||||
// Are there bells in the queue?
|
||||
bool Bellringer::bellPending() const {
|
||||
if (bells.is_empty())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
bool Bellringer::bellPending() const { return false; }
|
||||
|
||||
@ -1,30 +1,7 @@
|
||||
#include "./semaphore.h"
|
||||
#include "../interrupt/guard.h"
|
||||
#include "../thread/scheduler.h"
|
||||
uint8_t counter;
|
||||
Queue<Thread> waiting;
|
||||
Semaphore::Semaphore(unsigned c) {
|
||||
counter=c;
|
||||
}
|
||||
|
||||
Semaphore::Semaphore(unsigned c) { (void)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++;
|
||||
}
|
||||
|
||||
void Semaphore::p(Vault &vault) { (void)vault; }
|
||||
|
||||
void Semaphore::v(Vault &vault) { (void)vault; }
|
||||
|
||||
Loading…
Reference in New Issue