From e0024d9ea688ee91a77abc0e28c5ea24b13ca67d Mon Sep 17 00:00:00 2001 From: Amlal Date: Mon, 28 Oct 2024 07:01:58 +0100 Subject: IMP: Refactor whole source code to make it even. - That is because previously the source was both in lowercase and lettercase. Signed-off-by: Amlal --- dev/ZKAKit/src/Semaphore.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 dev/ZKAKit/src/Semaphore.cc (limited to 'dev/ZKAKit/src/Semaphore.cc') diff --git a/dev/ZKAKit/src/Semaphore.cc b/dev/ZKAKit/src/Semaphore.cc new file mode 100644 index 00000000..08f33cf1 --- /dev/null +++ b/dev/ZKAKit/src/Semaphore.cc @@ -0,0 +1,62 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#include +#include + +namespace Kernel +{ + Bool Semaphore::Unlock() noexcept + { + if (fLockingProcess) + fLockingProcess = nullptr; + + return fLockingProcess == nullptr; + } + + Bool Semaphore::Lock(UserProcess* process) + { + if (!process || fLockingProcess) + return false; + + fLockingProcess = process; + + return true; + } + + Bool Semaphore::IsLocked() const + { + return fLockingProcess; + } + + Bool Semaphore::LockOrWait(UserProcess* process, TimerInterface* timer) + { + if (process == nullptr) + return false; + + if (timer == nullptr) + return false; + + this->Lock(process); + + timer->Wait(); + + return this->Lock(process); + } + + /// @brief Wait with process, either wait for it to be being invalid, or not being run. + Void Semaphore::WaitForProcess() noexcept + { + while (fLockingProcess) + { + if (fLockingProcess->GetStatus() != ProcessStatusKind::kRunning) + { + this->Unlock(); + break; + } + } + } +} // namespace Kernel -- cgit v1.2.3