diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-16 16:42:09 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-16 16:42:09 +0100 |
| commit | 57921ca1d52dd3c3c988bf198b903c2da42f391a (patch) | |
| tree | b092732bc6c677536aed58366b149b17d1c46537 /dev/Kernel/src | |
| parent | 52779b9cc5b98ec201cc3a908a009469b4429647 (diff) | |
ADD: BinaryMutex class, and reworking Semaphore class.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/src')
| -rw-r--r-- | dev/Kernel/src/BinaryMutex.cc (renamed from dev/Kernel/src/Semaphore.cc) | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/dev/Kernel/src/Semaphore.cc b/dev/Kernel/src/BinaryMutex.cc index 20dd89e6..4fdaa8f4 100644 --- a/dev/Kernel/src/Semaphore.cc +++ b/dev/Kernel/src/BinaryMutex.cc @@ -5,14 +5,14 @@ ------------------------------------------- */ #include <KernelKit/UserProcessScheduler.h> -#include <KernelKit/Semaphore.h> +#include <KernelKit/BinaryMutex.h> namespace NeOS { /***********************************************************************************/ /// @brief Unlocks the semaphore. /***********************************************************************************/ - Bool Semaphore::Unlock() noexcept + Bool BinaryMutex::Unlock() noexcept { if (fLockingProcess) { @@ -27,7 +27,7 @@ namespace NeOS /***********************************************************************************/ /// @brief Locks process in the semaphore. /***********************************************************************************/ - Bool Semaphore::Lock(UserProcess& process) + Bool BinaryMutex::Lock(UserProcess& process) { if (!process || fLockingProcess) return No; @@ -40,7 +40,7 @@ namespace NeOS /***********************************************************************************/ /// @brief Checks if process is locked. /***********************************************************************************/ - Bool Semaphore::IsLocked() const + Bool BinaryMutex::IsLocked() const { return fLockingProcess.Status == ProcessStatusKind::kRunning; } @@ -48,7 +48,7 @@ namespace NeOS /***********************************************************************************/ /// @brief Try lock or wait. /***********************************************************************************/ - Bool Semaphore::LockOrWait(UserProcess& process, TimerInterface* timer) + Bool BinaryMutex::LockOrWait(UserProcess& process, TimerInterface* timer) { if (timer == nullptr) return No; @@ -61,11 +61,14 @@ namespace NeOS } /***********************************************************************************/ - /// @brief Wait for process to be free. + /// @brief Wait for process **sec** until we check if it's free. + /// @param sec seconds. /***********************************************************************************/ - Void Semaphore::WaitForProcess() noexcept + BOOL BinaryMutex::WaitForProcess(const Int16& sec) noexcept { - while (fLockingProcess) - ; + HardwareTimer hw_timer(rtl_seconds(sec)); + hw_timer.Wait(); + + return !this->IsLocked(); } } // namespace NeOS |
