diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-20 14:47:08 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-20 14:47:08 +0100 |
| commit | 4ba02280f19b8a2beb1ad8445be7df6b7f9e1805 (patch) | |
| tree | 4928e93b6463dcce6e0d74120882a6ec572bae5c /Private/KernelKit/LockDelegate.hpp | |
| parent | 055a896406af227e03708fa20a728259cace704a (diff) | |
kernel: Reworking kernel to support virtual memory.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/KernelKit/LockDelegate.hpp')
| -rw-r--r-- | Private/KernelKit/LockDelegate.hpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Private/KernelKit/LockDelegate.hpp b/Private/KernelKit/LockDelegate.hpp new file mode 100644 index 00000000..0fd9ba63 --- /dev/null +++ b/Private/KernelKit/LockDelegate.hpp @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Atom.hpp> +#include <NewKit/Defines.hpp> + +#define kLockDone (200U) /* job is done */ +#define kLockTimedOut (100U) /* job has timed out */ + +namespace HCore +{ +/// @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) + { + m_LockStatus | kLockDone; + break; + } + } + + if (spin == N) + m_LockStatus | kLockTimedOut; + } + + ~LockDelegate() = default; + + LockDelegate &operator=(const LockDelegate &) = delete; + LockDelegate(const LockDelegate &) = delete; + + bool Done() + { + return m_LockStatus[kLockDone] == kLockDone; + } + + bool HasTimedOut() + { + return m_LockStatus[kLockTimedOut] != kLockTimedOut; + } + + private: + Atom<UInt> m_LockStatus; +}; +} // namespace HCore |
