foo
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
|
|
||||||
#include "../arch/core.h"
|
#include "../arch/core.h"
|
||||||
#include "../debug/output.h"
|
#include "../debug/output.h"
|
||||||
#include "../object/bbuffer.h"
|
#include "../object/bbuffer.h"
|
||||||
@@ -28,7 +27,7 @@ Guarded Guard::enter() {
|
|||||||
epi_flag FOR_CURRENT_CORE = true;
|
epi_flag FOR_CURRENT_CORE = true;
|
||||||
Core::Interrupt::restore(status);
|
Core::Interrupt::restore(status);
|
||||||
global_lock.lock();
|
global_lock.lock();
|
||||||
|
Bellringer bellringer;
|
||||||
return Guarded(global_vault);
|
return Guarded(global_vault);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//#pragma once
|
//#pragma once
|
||||||
|
#include "sync/bellringer.h"
|
||||||
#include "../object/bbuffer.h"
|
#include "../object/bbuffer.h"
|
||||||
#include "../object/key.h"
|
#include "../object/key.h"
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
@@ -19,6 +20,8 @@ struct Vault {
|
|||||||
Vault(const Vault&) = delete;
|
Vault(const Vault&) = delete;
|
||||||
Vault& operator=(const Vault&) = delete;
|
Vault& operator=(const Vault&) = delete;
|
||||||
uint8_t counter;
|
uint8_t counter;
|
||||||
|
Bellringer bellringer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief Lock guard that provides access to the epilogue \ref Vault
|
/*! \brief Lock guard that provides access to the epilogue \ref Vault
|
||||||
|
|||||||
@@ -1,16 +1,38 @@
|
|||||||
#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)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.
|
// 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) {
|
||||||
(void)vault;
|
Bell bell;
|
||||||
(void)ms;
|
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?
|
// 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,15 +39,17 @@ void Application::action() { // NOLINT
|
|||||||
uint16_t cnt = 0;
|
uint16_t cnt = 0;
|
||||||
uint8_t row = appl_cnt++;
|
uint8_t row = appl_cnt++;
|
||||||
while (1) {
|
while (1) {
|
||||||
Guarded g= Guard::enter();
|
|
||||||
|
|
||||||
//koutlock.lock();
|
//koutlock.lock();
|
||||||
{
|
{
|
||||||
|
Guarded g= Guard::enter();
|
||||||
|
|
||||||
//g.vault();
|
//g.vault();
|
||||||
foo.p(g.vault());
|
foo.p(g.vault());
|
||||||
kout.setPos((unsigned)8*row,(unsigned)/*Core::getID()*2+*/1);
|
kout.setPos((unsigned)8*row,(unsigned)/*Core::getID()*2+*/1);
|
||||||
kout << cnt++ << flush;
|
kout << cnt++ << flush;
|
||||||
foo.v(g.vault());
|
foo.v(g.vault());
|
||||||
|
g.vault().bellringer.sleep(g.vault(),6666);
|
||||||
//g.vault().kout << endl << flush;
|
//g.vault().kout << endl << flush;
|
||||||
//Guard::leave();
|
//Guard::leave();
|
||||||
//koutlock.unlock();
|
//koutlock.unlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user