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.

39 lines
1.0 KiB
C++

#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);
}
}
}
// 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);
}
// Are there bells in the queue?
bool Bellringer::bellPending() const {
if (bells.is_empty())
return false;
else
return true;
}