diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
| commit | 5339d016c07bf717ee388f4feb73544087324af0 (patch) | |
| tree | 94be6f67ed626091f24aee24ec3b3be03d01e4e7 /KernelKit/Semaphore.hpp | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'KernelKit/Semaphore.hpp')
| -rw-r--r-- | KernelKit/Semaphore.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/KernelKit/Semaphore.hpp b/KernelKit/Semaphore.hpp new file mode 100644 index 00000000..03a724c8 --- /dev/null +++ b/KernelKit/Semaphore.hpp @@ -0,0 +1,46 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <NewKit/Defines.hpp> +#include <CompilerKit/Compiler.hpp> + +namespace hCore +{ + class Process; + + typedef Process* ProcessPtr; + + /// @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(Process* process); + bool LockOrWait(Process* process, const Int64& seconds); + + public: + HCORE_COPY_DEFAULT(Semaphore); + + private: + ProcessPtr fLockingProcess{ nullptr }; + + }; +} |
