NeKernel dev
Loading...
Searching...
No Matches
LockDelegate.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#pragma once
8
9#include <NeKit/Atom.h>
10#include <NeKit/Config.h>
11
12namespace Kernel {
13enum {
15 kLockDone = 200,
18};
19
22
25template <SizeT N>
26class LockDelegate final {
27 public:
28 LockDelegate() = delete;
29
30 public:
31 explicit LockDelegate(LockPtr expr) {
32 auto spin = 0U;
33
34 while (spin < N) {
35 if (*expr) {
37 break;
38 }
39
40 ++spin;
41 }
42
43 if (spin > N) fLockStatus | kLockTimedOut;
44 }
45
46 ~LockDelegate() = default;
47
49 LockDelegate(const LockDelegate&) = delete;
50
51 bool Done() { return fLockStatus[kLockDone] == kLockDone; }
52
54
55 private:
57};
58} // namespace Kernel
Definition Atom.h:12
bool Done()
Definition LockDelegate.h:51
bool HasTimedOut()
Definition LockDelegate.h:53
LockDelegate & operator=(const LockDelegate &)=delete
Atom< UInt > fLockStatus
Definition LockDelegate.h:56
LockDelegate(const LockDelegate &)=delete
LockDelegate(LockPtr expr)
Definition LockDelegate.h:31
UPS inline definitions.
Definition Device.h:12
Boolean * LockPtr
Lock condition pointer.
Definition LockDelegate.h:21
bool Boolean
Definition Config.h:49
@ kLockTimedOut
Definition LockDelegate.h:16
@ kLockDone
Definition LockDelegate.h:15
@ kLockInvalid
Definition LockDelegate.h:14
@ kLockCount
Definition LockDelegate.h:17