blob: cc5a7d3ce2e721435c139e8f1b0954c94e321e5b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\title{BinaryMutex: Technical Documentation}
\author{Amlal El Mahrouss}
\date{\today}
\begin{document}
\maketitle
\section{Abstract}
{The BinaryMutex is a core component of NeKernel (NeKernel/VMKernel) based systems. The pattern excludes other acquirers to own the USER\_PROCESS that is currently being hold. Thus the acquiree is the USER\_PROCESS itself}
\section{Use Case \#1: Process lock for atomic data retrival}
\begin{verbatim}
BinaryMutex mux;
mux.Lock(process);
// Say we want to interact with the process itself on this thread,
we can then make sure that no race condition happens by using:
constexpr auto kSecondsMax = 5;
mux.WaitForProcess(kSecondsMax);
process.DoFoo();
\end{verbatim}
\section{Implementation}
The source implementation consists of:
\begin{verbatim}
class BinaryMutex final {
public:
explicit BinaryMutex() = default;
~BinaryMutex() = default;
public:
bool IsLocked() const;
bool Unlock() noexcept;
public:
BOOL WaitForProcess(const UInt32& sec) noexcept;
public:
bool Lock(USER_PROCESS* process);
bool LockOrWait(USER_PROCESS* process, TimerInterface* timer);
public:
NE_COPY_DEFAULT(BinaryMutex)
private:
USER_PROCESS* fLockingProcess;
};
\end{verbatim}
\section{Conclusion}
This pattern is useful for systems that need to make sure that a process isn't tampered by concurrent usages. Thus its existence in VMKernel and NeKernel.
\end{document}
|