From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelKit/Semaphore.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Kernel/KernelKit/Semaphore.hpp (limited to 'Kernel/KernelKit/Semaphore.hpp') diff --git a/Kernel/KernelKit/Semaphore.hpp b/Kernel/KernelKit/Semaphore.hpp new file mode 100644 index 00000000..f12e1282 --- /dev/null +++ b/Kernel/KernelKit/Semaphore.hpp @@ -0,0 +1,42 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace NewOS +{ + class ProcessHeader; + + typedef ProcessHeader* ProcessHeaderRef; + + /// @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 Sync() noexcept; + + public: + bool Lock(ProcessHeader* process); + bool LockOrWait(ProcessHeader* process, const Int64& seconds); + + public: + NEWOS_COPY_DEFAULT(Semaphore); + + private: + ProcessHeaderRef fLockingProcess{nullptr}; + }; +} // namespace NewOS -- cgit v1.2.3