From 698d0c155be8d56db6e4d8e0962d5b04013f545b Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 8 Jul 2025 01:17:34 +0200 Subject: [PATCH] fixed scheduler in vault. insert borderline reference --- interrupt/guard.h | 7 ++++--- main.cc | 7 ++++--- thread/thread.cc | 8 ++++---- thread/thread.h | 1 - user/app1/appl.cc | 8 -------- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/interrupt/guard.h b/interrupt/guard.h index 2cfa0c2..e74b019 100644 --- a/interrupt/guard.h +++ b/interrupt/guard.h @@ -2,18 +2,19 @@ * \brief \ref Guard synchronizes access to epilogue level */ -#pragma once +//#pragma once #include "../object/bbuffer.h" #include "../object/key.h" #include "../types.h" #include "epilogues.h" #include "../device/textstream.h" - +#include "../thread/scheduler.h" //! \brief The epilogue vault contains the protected data for the epilogue level + struct Vault { Vault(); TextStream kout = TextStream(0, 80, 0, 10, true); - + Scheduler sch = Scheduler(); // no copy Vault(const Vault&) = delete; Vault& operator=(const Vault&) = delete; diff --git a/main.cc b/main.cc index 231614a..a581c0d 100644 --- a/main.cc +++ b/main.cc @@ -22,7 +22,7 @@ ///TextStream kout = TextStream(0, 80, 0, 10, true); Ticketlock koutlock; -Scheduler sch; +//Scheduler sch; //TextStream dout[8] = { // TextStream(0 ,20,12,25,false), @@ -108,6 +108,7 @@ extern "C" int main() { { Guarded g = Guard::enter(); + Scheduler &sch =g.vault().sch; sch.ready(&application1); sch.ready(&application2); sch.ready(&application3); @@ -140,7 +141,7 @@ extern "C" int main() { { Guarded g = Guard::enter(); - sch.schedule(); + g.vault().sch.schedule(); } @@ -163,7 +164,7 @@ extern "C" int main_ap() { { Guarded g = Guard::enter(); - sch.schedule(); + g.vault().sch.schedule(); } //assert(Core::getID() != 1); diff --git a/thread/thread.cc b/thread/thread.cc index b34c556..7d487e1 100644 --- a/thread/thread.cc +++ b/thread/thread.cc @@ -3,7 +3,7 @@ #include "thread.h" #include "../debug/output.h" #include "../arch/context.h" - +#include "interrupt/guard.h" // Alias to simplify stuff typedef void (*kickoff_t)(void*); @@ -17,12 +17,12 @@ Thread::Thread(void* tos) { } #include "../thread/scheduler.h" -extern Scheduler sch; void Thread::resume(Thread* next) { - Context *from = &sch.active()->context; + Guarded g = Guard::enter(); + Context *from = &g.vault().sch.active()->context; Context *to = &next->context; - sch.dispatcher.lifePointer[Core::getID()] = next; + g.vault().sch.dispatcher.lifePointer[Core::getID()] = next; DBG << "from: " << hex << from << endl; DBG << "to : " << hex << to << endl << flush; context_switch(to, from); diff --git a/thread/thread.h b/thread/thread.h index 4fe032a..8144433 100644 --- a/thread/thread.h +++ b/thread/thread.h @@ -16,7 +16,6 @@ #include "../arch/context.h" #include "../object/queue.h" #include "../types.h" -#include "../interrupt/guard.h" /*! \brief The Thread is an object used by the scheduler. * \ingroup thread */ diff --git a/user/app1/appl.cc b/user/app1/appl.cc index 3d045fe..3ca2ed8 100644 --- a/user/app1/appl.cc +++ b/user/app1/appl.cc @@ -9,9 +9,7 @@ #include "../../interrupt/guard.h" #include "../../debug/output.h" #include "../../arch/context.h" -#include "../../thread/scheduler.h" -extern Scheduler sch; static uint8_t appl_cnt = 0; char text[] = "Ich mag\n\ @@ -57,12 +55,6 @@ void Application::action() { // NOLINT //Core::pause(); //activeWaitDelay(10000000); - - //{ - // Guarded g = Guard::enter(); - // sch.resume(true); - //} - if(cnt >= sizeof(text)-1) cnt=0; //context_switch(test2,test1);