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 | |
| parent | 52779b9cc5b98ec201cc3a908a009469b4429647 (diff) | |
ADD: BinaryMutex class, and reworking Semaphore class.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc | 2 | ||||
| -rw-r--r-- | dev/Kernel/KernelKit/BinaryMutex.h | 43 | ||||
| -rw-r--r-- | dev/Kernel/KernelKit/Semaphore.h | 29 | ||||
| -rw-r--r-- | dev/Kernel/doc/SPECIFICATION.md | 2 | ||||
| -rw-r--r-- | dev/Kernel/src/BinaryMutex.cc (renamed from dev/Kernel/src/Semaphore.cc) | 21 |
5 files changed, 58 insertions, 39 deletions
diff --git a/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc index 7a9c83bc..38d31d48 100644 --- a/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -8,7 +8,7 @@ #include <KernelKit/UserProcessScheduler.h> #include <HALKit/AMD64/Processor.h> #include <ArchKit/ArchKit.h> -#include <KernelKit/Semaphore.h> +#include <KernelKit/BinaryMutex.h> #include <KernelKit/UserProcessScheduler.h> #include <KernelKit/Timer.h> #include <Mod/CoreGfx/TextMgr.h> diff --git a/dev/Kernel/KernelKit/BinaryMutex.h b/dev/Kernel/KernelKit/BinaryMutex.h new file mode 100644 index 00000000..a8e18abf --- /dev/null +++ b/dev/Kernel/KernelKit/BinaryMutex.h @@ -0,0 +1,43 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.h> +#include <KernelKit/Timer.h> +#include <CompilerKit/CompilerKit.h> + +namespace NeOS +{ + class UserProcess; + + typedef UserProcess& UserProcessRef; + + /// @brief Access control class, which locks a task until one is done. + class BinaryMutex final + { + public: + explicit BinaryMutex() = default; + ~BinaryMutex() = default; + + public: + bool IsLocked() const; + bool Unlock() noexcept; + + public: + BOOL WaitForProcess(const Int16& sec) noexcept; + + public: + bool Lock(UserProcess& process); + bool LockOrWait(UserProcess& process, TimerInterface* timer); + + public: + NE_COPY_DEFAULT(BinaryMutex); + + private: + UserProcessRef fLockingProcess; + }; +} // namespace NeOS diff --git a/dev/Kernel/KernelKit/Semaphore.h b/dev/Kernel/KernelKit/Semaphore.h index 5d77b84d..f780872a 100644 --- a/dev/Kernel/KernelKit/Semaphore.h +++ b/dev/Kernel/KernelKit/Semaphore.h @@ -12,32 +12,5 @@ namespace NeOS { - class UserProcess; - typedef UserProcess& UserProcessRef; - - /// @brief Access control class, which locks a task until one is done. - class Semaphore final - { - public: - explicit Semaphore() = default; - ~Semaphore() = default; - - public: - bool IsLocked() const; - bool Unlock() noexcept; - - public: - void WaitForProcess() noexcept; - - public: - bool Lock(UserProcess& process); - bool LockOrWait(UserProcess& process, TimerInterface* timer); - - public: - NE_COPY_DEFAULT(Semaphore); - - private: - UserProcessRef fLockingProcess; - }; -} // namespace NeOS +} // namespace NeOS
\ No newline at end of file diff --git a/dev/Kernel/doc/SPECIFICATION.md b/dev/Kernel/doc/SPECIFICATION.md index b2da5e8c..2cdee1f0 100644 --- a/dev/Kernel/doc/SPECIFICATION.md +++ b/dev/Kernel/doc/SPECIFICATION.md @@ -22,7 +22,7 @@ - Native Filesystem support (NeFS, FAT32 and ffs2). - Program Loaders interfaces. - TLS (Thread Local Storage) support. -- Semaphore, Locks, Timers. +- BinaryMutex, Locks, Timers. - Canary mechanisms. - Dynamic Sys. - Cross Platform. 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 |
