From 42f2dd602896c223c9996a4e74b6647f4c734b54 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 13 Jul 2025 16:34:52 +0200 Subject: [PATCH] fooo --- interrupt/guard.cc | 4 +++- interrupt/guard.h | 1 + sync/semaphore.cc | 28 +++++++++++++++++++++++++--- thread/scheduler.cc | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/interrupt/guard.cc b/interrupt/guard.cc index 20c47ed..345a2b3 100644 --- a/interrupt/guard.cc +++ b/interrupt/guard.cc @@ -24,9 +24,11 @@ Vault::Vault() { Guarded::~Guarded() { Guard::leave(); } Guarded Guard::enter() { + bool status = Core::Interrupt::disable(); epi_flag FOR_CURRENT_CORE = true; - //Core::Interrupt::enable(); + Core::Interrupt::restore(status); global_lock.lock(); + return Guarded(global_vault); } diff --git a/interrupt/guard.h b/interrupt/guard.h index e74b019..290f554 100644 --- a/interrupt/guard.h +++ b/interrupt/guard.h @@ -18,6 +18,7 @@ struct Vault { // no copy Vault(const Vault&) = delete; Vault& operator=(const Vault&) = delete; + uint8_t counter; }; /*! \brief Lock guard that provides access to the epilogue \ref Vault diff --git a/sync/semaphore.cc b/sync/semaphore.cc index b026d67..7ee3142 100644 --- a/sync/semaphore.cc +++ b/sync/semaphore.cc @@ -1,7 +1,29 @@ #include "./semaphore.h" +#include "../interrupt/guard.h" +#include "../thread/scheduler.h" +uint8_t counter; +Queue waiting; +Semaphore::Semaphore(unsigned c) { + counter=c; +} -Semaphore::Semaphore(unsigned c) { (void)c; } -void Semaphore::p(Vault &vault) { (void)vault; } +void Semaphore::p(Vault &vault) { + //resource is frei, läuft direkt weiter + if (vault.counter > 0) + vault.counter--; + //else + /// thread block, zu aktueller queue hinzufügen und +// vault.sch.block(this); +} + +//release +void Semaphore::v(Vault &vault) { + //Thread* first = waiting.dequeue(); + //if (first != nullptr) + // void Scheduler::wakeup(first); + //else + vault.counter++; +} + -void Semaphore::v(Vault &vault) { (void)vault; } diff --git a/thread/scheduler.cc b/thread/scheduler.cc index 9df4423..a35878d 100644 --- a/thread/scheduler.cc +++ b/thread/scheduler.cc @@ -62,6 +62,9 @@ bool Scheduler::isActive(const Thread* thread, unsigned int* cpu) { return false; } + + + bool Scheduler::isEmpty() const { return false; } void Scheduler::setIdle(IdleThread* that) { (void)that; }