diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
| commit | 5339d016c07bf717ee388f4feb73544087324af0 (patch) | |
| tree | 94be6f67ed626091f24aee24ec3b3be03d01e4e7 /NewKit/LockDelegate.hpp | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'NewKit/LockDelegate.hpp')
| -rw-r--r-- | NewKit/LockDelegate.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/NewKit/LockDelegate.hpp b/NewKit/LockDelegate.hpp new file mode 100644 index 00000000..87ad1914 --- /dev/null +++ b/NewKit/LockDelegate.hpp @@ -0,0 +1,60 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <NewKit/Atom.hpp> +#include <NewKit/Defines.hpp> + +#define kLockDone (200U) /* job is done */ +#define kLockTimedOut (100U) /* has timed out */ + +namespace hCore +{ +template <Size N> +class LockDelegate final +{ + public: + LockDelegate() = delete; + + public: + explicit LockDelegate(Boolean *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 |
