This commit is contained in:
Simon
2025-07-14 16:46:33 +02:00
parent 9d525a9602
commit 6951311c9c
4 changed files with 34 additions and 8 deletions

View File

@@ -1,16 +1,38 @@
#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) { (void)vault; }
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);
}
}
}
// job: Give a bell to the bellringer & ring it when the specified time ran out.
void Bellringer::sleep(Vault &vault, unsigned int ms) {
(void)vault;
(void)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);
}
// Are there bells in the queue?
bool Bellringer::bellPending() const { return false; }
bool Bellringer::bellPending() const {
if (bells.is_empty())
return false;
else
return true;
}