From 6951311c9c533ad5e86383278ca9b166ac9ed5b1 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 14 Jul 2025 16:46:33 +0200 Subject: [PATCH] foo --- interrupt/guard.cc | 3 +-- interrupt/guard.h | 3 +++ sync/bellringer.cc | 32 +++++++++++++++++++++++++++----- user/app1/appl.cc | 4 +++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/interrupt/guard.cc b/interrupt/guard.cc index 345a2b3..8f647b1 100644 --- a/interrupt/guard.cc +++ b/interrupt/guard.cc @@ -1,5 +1,4 @@ #include "guard.h" - #include "../arch/core.h" #include "../debug/output.h" #include "../object/bbuffer.h" @@ -28,7 +27,7 @@ Guarded Guard::enter() { epi_flag FOR_CURRENT_CORE = true; Core::Interrupt::restore(status); global_lock.lock(); - + Bellringer bellringer; return Guarded(global_vault); } diff --git a/interrupt/guard.h b/interrupt/guard.h index 290f554..ee7dcff 100644 --- a/interrupt/guard.h +++ b/interrupt/guard.h @@ -3,6 +3,7 @@ */ //#pragma once +#include "sync/bellringer.h" #include "../object/bbuffer.h" #include "../object/key.h" #include "../types.h" @@ -19,6 +20,8 @@ struct Vault { Vault(const Vault&) = delete; Vault& operator=(const Vault&) = delete; uint8_t counter; + Bellringer bellringer; + }; /*! \brief Lock guard that provides access to the epilogue \ref Vault diff --git a/sync/bellringer.cc b/sync/bellringer.cc index 8836380..f883d5e 100644 --- a/sync/bellringer.cc +++ b/sync/bellringer.cc @@ -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; +} diff --git a/user/app1/appl.cc b/user/app1/appl.cc index a04283e..a373316 100644 --- a/user/app1/appl.cc +++ b/user/app1/appl.cc @@ -39,15 +39,17 @@ void Application::action() { // NOLINT uint16_t cnt = 0; uint8_t row = appl_cnt++; while (1) { - Guarded g= Guard::enter(); //koutlock.lock(); { + Guarded g= Guard::enter(); + //g.vault(); foo.p(g.vault()); kout.setPos((unsigned)8*row,(unsigned)/*Core::getID()*2+*/1); kout << cnt++ << flush; foo.v(g.vault()); + g.vault().bellringer.sleep(g.vault(),6666); //g.vault().kout << endl << flush; //Guard::leave(); //koutlock.unlock();