From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/zka/KernelKit/LockDelegate.h | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 dev/zka/KernelKit/LockDelegate.h (limited to 'dev/zka/KernelKit/LockDelegate.h') diff --git a/dev/zka/KernelKit/LockDelegate.h b/dev/zka/KernelKit/LockDelegate.h new file mode 100644 index 00000000..8f7e9a42 --- /dev/null +++ b/dev/zka/KernelKit/LockDelegate.h @@ -0,0 +1,67 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace Kernel +{ + enum + { + kLockDone = 200, + kLockTimedOut, + }; + + /// @brief Lock condition pointer. + typedef Boolean* LockPtr; + + /// @brief Locking delegate class, hangs until limit. + /// @tparam N the amount of cycles to wait. + template + class LockDelegate final + { + public: + LockDelegate() = delete; + + public: + explicit LockDelegate(LockPtr expr) + { + auto spin = 0U; + + while (spin != N) + { + if (*expr) + { + fLockStatus | kLockDone; + break; + } + } + + 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 fLockStatus; + }; +} // namespace Kernel -- cgit v1.2.3