summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/BinaryMutex.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-02 19:38:46 +0200
committerGitHub <noreply@github.com>2025-05-02 19:38:46 +0200
commit997be16e5ac9a68d54882ab69529815860d62955 (patch)
tree19d6129c2d776bb1edc5d4a7325e39ca176c3403 /dev/kernel/src/BinaryMutex.cc
parent618104e74c195d7508a18450524f8ed7f9af8cc6 (diff)
parentb3b4b1ebdcd6adeac914869017c86d892b7a8ced (diff)
Merge pull request #28 from nekernel-org/dev
0.0.2
Diffstat (limited to 'dev/kernel/src/BinaryMutex.cc')
-rw-r--r--dev/kernel/src/BinaryMutex.cc126
1 files changed, 59 insertions, 67 deletions
diff --git a/dev/kernel/src/BinaryMutex.cc b/dev/kernel/src/BinaryMutex.cc
index 1ed08fa9..8bf1432e 100644
--- a/dev/kernel/src/BinaryMutex.cc
+++ b/dev/kernel/src/BinaryMutex.cc
@@ -1,74 +1,66 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
-#include <KernelKit/ProcessScheduler.h>
#include <KernelKit/BinaryMutex.h>
+#include <KernelKit/ProcessScheduler.h>
+
+namespace Kernel {
+/***********************************************************************************/
+/// @brief Unlocks the binary mutex.
+/***********************************************************************************/
+Bool BinaryMutex::Unlock() noexcept {
+ if (fLockingProcess) {
+ fLockingProcess = USER_PROCESS();
+ fLockingProcess.Status = ProcessStatusKind::kFrozen;
+
+ return Yes;
+ }
+
+ return No;
+}
+
+/***********************************************************************************/
+/// @brief Locks process in the binary mutex.
+/***********************************************************************************/
+Bool BinaryMutex::Lock(USER_PROCESS& process) {
+ if (!process || this->IsLocked()) return No;
+
+ this->fLockingProcess = process;
+
+ return Yes;
+}
+
+/***********************************************************************************/
+/// @brief Checks if process is locked.
+/***********************************************************************************/
+Bool BinaryMutex::IsLocked() const {
+ return this->fLockingProcess.Status == ProcessStatusKind::kRunning;
+}
+
+/***********************************************************************************/
+/// @brief Try lock or wait.
+/***********************************************************************************/
+Bool BinaryMutex::LockOrWait(USER_PROCESS& process, TimerInterface* timer) {
+ if (timer == nullptr) return No;
+
+ this->Lock(process);
+
+ timer->Wait();
+
+ return this->Lock(process);
+}
+
+/***********************************************************************************/
+/// @brief Wait for process **sec** until we check if it's free.
+/// @param sec seconds.
+/***********************************************************************************/
+BOOL BinaryMutex::WaitForProcess(const Int16& sec) noexcept {
+ HardwareTimer hw_timer(rtl_milliseconds(sec));
+ hw_timer.Wait();
-namespace Kernel
-{
- /***********************************************************************************/
- /// @brief Unlocks the semaphore.
- /***********************************************************************************/
- Bool BinaryMutex::Unlock() noexcept
- {
- if (fLockingProcess)
- {
- fLockingProcess = Process();
- fLockingProcess.Status = ProcessStatusKind::kFrozen;
- return Yes;
- }
-
- return No;
- }
-
- /***********************************************************************************/
- /// @brief Locks process in the semaphore.
- /***********************************************************************************/
- Bool BinaryMutex::Lock(Process& process)
- {
- if (!process || fLockingProcess)
- return No;
-
- fLockingProcess = process;
-
- return Yes;
- }
-
- /***********************************************************************************/
- /// @brief Checks if process is locked.
- /***********************************************************************************/
- Bool BinaryMutex::IsLocked() const
- {
- return fLockingProcess.Status == ProcessStatusKind::kRunning;
- }
-
- /***********************************************************************************/
- /// @brief Try lock or wait.
- /***********************************************************************************/
- Bool BinaryMutex::LockOrWait(Process& process, TimerInterface* timer)
- {
- if (timer == nullptr)
- return No;
-
- this->Lock(process);
-
- timer->Wait();
-
- return this->Lock(process);
- }
-
- /***********************************************************************************/
- /// @brief Wait for process **sec** until we check if it's free.
- /// @param sec seconds.
- /***********************************************************************************/
- BOOL BinaryMutex::WaitForProcess(const Int16& sec) noexcept
- {
- HardwareTimer hw_timer(rtl_seconds(sec));
- hw_timer.Wait();
-
- return !this->IsLocked();
- }
-} // namespace Kernel
+ return !this->IsLocked();
+}
+} // namespace Kernel