blob: c589866c701e72992c3453f8aa98bc3608c59b98 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Copyright (C) Microsoft Corporation. All rights reserved.
#pragma once
#include <KMacros.h>
#include <KCriticalRegion.h>
typedef struct _KTHREAD *PKTHREAD;
// Copyright (C) Microsoft Corporation. All rights reserved.
class KPushLockBase
{
public:
KPushLockBase() = default;
KPushLockBase(KPushLockBase &) = delete;
KPushLockBase & operator=(KPushLockBase &) = delete;
PAGED
void
KPushLockBase::AcquireShared()
{
#ifdef _KERNEL_MODE
ExAcquirePushLockShared(&m_Lock);
#else
AcquireSRWLockShared(&m_Lock);
#endif
}
PAGED
void
KPushLockBase::ReleaseShared()
{
#ifdef _KERNEL_MODE
ExReleasePushLockShared(&m_Lock);
#else
ReleaseSRWLockShared(&m_Lock);
#endif
}
PAGED
void
KPushLockBase::AcquireExclusive()
{
#ifdef _KERNEL_MODE
ExAcquirePushLockExclusive(&m_Lock);
#if DBG
m_ExclusiveOwner = KeGetCurrentThread();
#endif
#else
AcquireSRWLockExclusive(&m_Lock);
#endif
}
PAGED
void
KPushLockBase::ReleaseExclusive()
{
#if DBG
m_ExclusiveOwner = nullptr;
#endif
#ifdef _KERNEL_MODE
ExReleasePushLockExclusive(&m_Lock);
#else
ReleaseSRWLockExclusive(&m_Lock);
#endif
}
PAGED
void
KPushLockBase::AssertLockHeld()
{
#ifdef _KERNEL_MODE
WIN_ASSERT(m_ExclusiveOwner == KeGetCurrentThread());
#endif
}
PAGED
void
KPushLockBase::AssertLockNotHeld()
{
#if DBG && defined(_KERNEL_MODE)
WIN_ASSERT(m_ExclusiveOwner != KeGetCurrentThread());
#endif
}
protected:
PAGED
void
KPushLockBase::InitializeInner()
{
#ifdef _KERNEL_MODE
ExInitializePushLock(&m_Lock);
#else
InitializeSRWLock(&m_Lock);
#endif
#if DBG
m_ExclusiveOwner = nullptr;
#endif
}
private:
#ifdef _KERNEL_MODE
EX_PUSH_LOCK m_Lock;
#else
SRWLOCK m_Lock;
#endif
#if DBG
PKTHREAD m_ExclusiveOwner;
#endif
};
class KPushLock : public KPushLockBase
{
public:
PAGED
KPushLock::KPushLock() noexcept
{
InitializeInner();
}
PAGED
KPushLock::~KPushLock()
{
AssertLockNotHeld();
}
};
class KPushLockManualConstruct : public KPushLockBase
{
public:
PAGED
void
KPushLockManualConstruct::Initialize()
{
InitializeInner();
}
};
|