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