From 57921ca1d52dd3c3c988bf198b903c2da42f391a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 16 Mar 2025 16:42:09 +0100 Subject: ADD: BinaryMutex class, and reworking Semaphore class. Signed-off-by: Amlal El Mahrouss --- dev/Kernel/src/Semaphore.cc | 71 --------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 dev/Kernel/src/Semaphore.cc (limited to 'dev/Kernel/src/Semaphore.cc') diff --git a/dev/Kernel/src/Semaphore.cc b/dev/Kernel/src/Semaphore.cc deleted file mode 100644 index 20dd89e6..00000000 --- a/dev/Kernel/src/Semaphore.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -namespace NeOS -{ - /***********************************************************************************/ - /// @brief Unlocks the semaphore. - /***********************************************************************************/ - Bool Semaphore::Unlock() noexcept - { - if (fLockingProcess) - { - fLockingProcess = UserProcess(); - fLockingProcess.Status = ProcessStatusKind::kFrozen; - return Yes; - } - - return No; - } - - /***********************************************************************************/ - /// @brief Locks process in the semaphore. - /***********************************************************************************/ - Bool Semaphore::Lock(UserProcess& process) - { - if (!process || fLockingProcess) - return No; - - fLockingProcess = process; - - return Yes; - } - - /***********************************************************************************/ - /// @brief Checks if process is locked. - /***********************************************************************************/ - Bool Semaphore::IsLocked() const - { - return fLockingProcess.Status == ProcessStatusKind::kRunning; - } - - /***********************************************************************************/ - /// @brief Try lock or wait. - /***********************************************************************************/ - Bool Semaphore::LockOrWait(UserProcess& process, TimerInterface* timer) - { - if (timer == nullptr) - return No; - - this->Lock(process); - - timer->Wait(); - - return this->Lock(process); - } - - /***********************************************************************************/ - /// @brief Wait for process to be free. - /***********************************************************************************/ - Void Semaphore::WaitForProcess() noexcept - { - while (fLockingProcess) - ; - } -} // namespace NeOS -- cgit v1.2.3