summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/LockDelegate.h
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/KernelKit/LockDelegate.h
parent618104e74c195d7508a18450524f8ed7f9af8cc6 (diff)
parentb3b4b1ebdcd6adeac914869017c86d892b7a8ced (diff)
Merge pull request #28 from nekernel-org/dev
0.0.2
Diffstat (limited to 'dev/kernel/KernelKit/LockDelegate.h')
-rw-r--r--dev/kernel/KernelKit/LockDelegate.h109
1 files changed, 48 insertions, 61 deletions
diff --git a/dev/kernel/KernelKit/LockDelegate.h b/dev/kernel/KernelKit/LockDelegate.h
index ac54d9c5..18ab0cf5 100644
--- a/dev/kernel/KernelKit/LockDelegate.h
+++ b/dev/kernel/KernelKit/LockDelegate.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -9,63 +9,50 @@
#include <NewKit/Atom.h>
#include <NewKit/Defines.h>
-namespace Kernel
-{
- enum
- {
- kLockInvalid,
- kLockDone = 200,
- kLockTimedOut,
- kLockCount = 3,
- };
-
- /// @brief Lock condition pointer.
- typedef Boolean* LockPtr;
-
- /// @brief Locking delegate class, hangs until limit.
- /// @tparam N the amount of cycles to wait.
- template <SizeT N>
- class LockDelegate final
- {
- public:
- LockDelegate() = delete;
-
- public:
- explicit LockDelegate(LockPtr expr)
- {
- auto spin = 0U;
-
- while (spin < N)
- {
- if (*expr)
- {
- fLockStatus | kLockDone;
- break;
- }
-
- ++spin;
- }
-
- if (spin > N)
- fLockStatus | kLockTimedOut;
- }
-
- ~LockDelegate() = default;
-
- LockDelegate& operator=(const LockDelegate&) = delete;
- LockDelegate(const LockDelegate&) = delete;
-
- bool Done()
- {
- return fLockStatus[kLockDone] == kLockDone;
- }
-
- bool HasTimedOut()
- {
- return fLockStatus[kLockTimedOut] != kLockTimedOut;
- }
-
- private:
- Atom<UInt> fLockStatus;
- };
-} // namespace Kernel
+namespace Kernel {
+enum {
+ kLockInvalid,
+ kLockDone = 200,
+ kLockTimedOut,
+ kLockCount = 3,
+};
+
+/// @brief Lock condition pointer.
+typedef Boolean* LockPtr;
+
+/// @brief Locking delegate class, hangs until limit.
+/// @tparam N the amount of cycles to wait.
+template <SizeT N>
+class LockDelegate final {
+ public:
+ LockDelegate() = delete;
+
+ public:
+ explicit LockDelegate(LockPtr expr) {
+ auto spin = 0U;
+
+ while (spin < N) {
+ if (*expr) {
+ fLockStatus | kLockDone;
+ break;
+ }
+
+ ++spin;
+ }
+
+ if (spin > N) fLockStatus | kLockTimedOut;
+ }
+
+ ~LockDelegate() = default;
+
+ LockDelegate& operator=(const LockDelegate&) = delete;
+ LockDelegate(const LockDelegate&) = delete;
+
+ bool Done() { return fLockStatus[kLockDone] == kLockDone; }
+
+ bool HasTimedOut() { return fLockStatus[kLockTimedOut] != kLockTimedOut; }
+
+ private:
+ Atom<UInt> fLockStatus;
+};
+} // namespace Kernel