summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/Sources/Semaphore.cxx
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
commitf3d931aa7cfaf96baef8383b59a8938779541ee7 (patch)
treefdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/Sources/Semaphore.cxx
parent86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff)
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/Sources/Semaphore.cxx')
-rw-r--r--dev/Kernel/Sources/Semaphore.cxx62
1 files changed, 62 insertions, 0 deletions
diff --git a/dev/Kernel/Sources/Semaphore.cxx b/dev/Kernel/Sources/Semaphore.cxx
new file mode 100644
index 00000000..c159240e
--- /dev/null
+++ b/dev/Kernel/Sources/Semaphore.cxx
@@ -0,0 +1,62 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/ProcessScheduler.hxx>
+#include <KernelKit/Semaphore.hxx>
+
+namespace Kernel
+{
+ bool Semaphore::Unlock() noexcept
+ {
+ if (fLockingProcess)
+ fLockingProcess = nullptr;
+
+ return fLockingProcess == nullptr;
+ }
+
+ bool Semaphore::Lock(PROCESS_HEADER_BLOCK* process)
+ {
+ if (!process || fLockingProcess)
+ return false;
+
+ fLockingProcess = process;
+
+ return true;
+ }
+
+ bool Semaphore::IsLocked() const
+ {
+ return fLockingProcess;
+ }
+
+ bool Semaphore::LockOrWait(PROCESS_HEADER_BLOCK* process, HardwareTimerInterface* timer)
+ {
+ if (process == nullptr)
+ return false;
+
+ if (timer == nullptr)
+ return false;
+
+ this->Lock(process);
+
+ timer->Wait();
+
+ return this->Lock(process);
+ }
+
+ /// @brief Wait with process, either wait for process being invalid, or not being run.
+ Void Semaphore::WaitForProcess() noexcept
+ {
+ while (fLockingProcess)
+ {
+ if (fLockingProcess->GetStatus() != ProcessStatus::kRunning)
+ {
+ this->Unlock();
+ break;
+ }
+ }
+ }
+} // namespace Kernel