ReactOS 0.4.15-dev-7788-g1ad9096
fxwaitlock.hpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxWaitLock.hpp
8
9Abstract:
10
11--*/
12
13#ifndef _FXWAITLOCK_HPP_
14#define _FXWAITLOCK_HPP_
15
16struct FxCREvent {
19 )
20 {
21 //
22 // For kernel mode letting c'tor do the initialization to not churn the
23 // non-shared code
24 //
25#if (FX_CORE_MODE==FX_CORE_KERNEL_MODE)
27#else
29#endif
30 }
31
32
33
34
35
39 )
40 {
41#if (FX_CORE_MODE==FX_CORE_KERNEL_MODE)
43#else
46#endif
47 }
48
53 )
54 {
56 }
57
63 )
64 {
66 }
67
68 __drv_valueIs(==0;==258)
69 _Acquires_lock_(_Global_critical_region_)
71 EnterCRAndWait(
72 VOID
73 )
74 {
76
77 Mx::MxEnterCriticalRegion();
78
81 FALSE,
82 NULL);
83 return status;
84 }
85
88 VOID
89 )
90 {
92
93 status = EnterCRAndWait();
94 LeaveCR();
95
96 return status;
97 }
98
102 _Acquires_lock_(_Global_critical_region_)
104 EnterCRAndWait(
106 )
107 {
109
110 Mx::MxEnterCriticalRegion();
111
114 FALSE,
116
117 return status;
118 }
119
124 )
125 {
127
128 status = EnterCRAndWait(Timeout);
129 LeaveCR();
130
131 return status;
132 }
133
134 _Releases_lock_(_Global_critical_region_)
135 VOID
136 LeaveCR(
137 VOID
138 )
139 {
140 Mx::MxLeaveCriticalRegion();
141 }
142
143 VOID
145 VOID
146 )
147 {
148 m_Event.Set();
149 }
150
151 VOID
153 VOID
154 )
155 {
156 m_Event.Clear();
157 }
158
159 LONG
161 VOID
162 )
163 {
164 return m_Event.ReadState();
165 }
166
167 //
168 // Return the underlying event
169 // PKEVENT in kernel mode and event HANDLE in user-mode
170 //
171 PVOID
173 VOID
174 )
175 {
176 return m_Event.GetEvent();
177 }
178
179 FxCREvent*
181 VOID
182 )
183 {
184 //
185 // Since operator& is hidden, we still need to be able to get a pointer
186 // to this object, so we must make it an explicit method.
187 //
188 return this;
189 }
190private:
192 VOID
193 )
194 {
195 //
196 // By making the address of operator private, we make it harder (hopefully
197 // impossible) to accidentally use this object in an improper fashion, ie
198 // something like this is prevented:
199 //
200 // FxCREvent event;
201 // KeWaitForSingleObject(&event, ...);
202 //
203 ASSERT(FALSE);
204 return NULL;
205 }
206
207private:
209};
210
211//
212// Non referencable object, just pure implementation
213//
215
216public:
217
219 VOID
220 )
221 {
222 //
223 // For kernel mode letting c'tor do the initialization to not churn the
224 // non-shared code
225 //
226#if (FX_CORE_MODE==FX_CORE_KERNEL_MODE)
227 m_Event.Initialize(SynchronizationEvent, TRUE);
228#endif
229
231 }
232
236 )
237 {
238 return m_Event.Initialize(SynchronizationEvent, TRUE);
239 }
240
241 //
242
243 //
247 _When_(return!=0x00000102L, _Acquires_lock_(_Global_critical_region_))
250 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
252 )
253 {
256
257 UNREFERENCED_PARAMETER(FxDriverGlobals);
258
260
261 if (Timeout != NULL) {
263 }
264
265 Mx::MxEnterCriticalRegion();
266 status = m_Event.WaitFor(Executive,
268 FALSE,
269 Timeout == NULL ? NULL : &li);
270
271 if (status == STATUS_TIMEOUT) {
272 Mx::MxLeaveCriticalRegion();
273 }
274 else {
276 }
277
278 return status;
279 }
280
281 static
282 BOOLEAN
283 IsLockAcquired(
285 )
286 {
287 //
288 // STATUS_TIMEOUT will return TRUE for NT_SUCCESS so check explicitly
289 //
290 return (NT_SUCCESS(Status) && Status != STATUS_TIMEOUT) ? TRUE : FALSE;
291 }
292
293 _Releases_lock_(_Global_critical_region_)
294 VOID
296 __in PFX_DRIVER_GLOBALS FxDriverGlobals
297 )
298 {
299 UNREFERENCED_PARAMETER(FxDriverGlobals);
300
303
304 m_Event.Set();
305 Mx::MxLeaveCriticalRegion();
306 }
307
308protected:
309 MxEvent m_Event;
310
312};
313
314
315//
316// Order is important here, FxObject *must* be the first class in the
317// list so that &FxWaitWaitLock == &FxNonPagedObject.
318//
319class FxWaitLock : public FxObject, public FxWaitLockInternal {
320
321public:
322 // Factory function
324 static
326 _Create(
329 __in_opt FxObject* ParentObject,
330 __in BOOLEAN AssignDriverAsDefaultParent,
331 __out WDFWAITLOCK* LockHandle
332 );
333
334
338 )
339 {
340 return FxWaitLockInternal::Initialize(); // __super call
341 }
342
344 __in PFX_DRIVER_GLOBALS FxDriverGlobals
345 ) :
346 FxObject(FX_TYPE_WAIT_LOCK, sizeof(FxWaitLock), FxDriverGlobals)
347 {
348 }
349};
350
351#endif // _FXWAITLOCK_HPP_
unsigned char BOOLEAN
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
return
Definition: dirsup.c:529
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize()
Definition: fxwaitlock.hpp:235
_Must_inspect_result_ __in_opt PLONGLONG Timeout
Definition: fxwaitlock.hpp:251
__drv_valueIs(==0;==258)) __drv_when(Timeout !
__drv_when(Timeout==NULL, __drv_valueIs(==0)) __drv_when(Timeout !
MxThread m_OwningThread
Definition: fxwaitlock.hpp:311
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize()
Definition: fxwaitlock.hpp:337
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in_opt FxObject *ParentObject, __in BOOLEAN AssignDriverAsDefaultParent, __out WDFWAITLOCK *LockHandle)
Definition: fxwaitlock.cpp:32
FxWaitLock(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxwaitlock.hpp:343
_Must_inspect_result_ __inline NTSTATUS WaitFor(__in KWAIT_REASON WaitReason, __in KPROCESSOR_MODE WaitMode, __in BOOLEAN Alertable, __in_opt PLARGE_INTEGER Timeout)
Definition: mxeventkm.h:115
__inline VOID Clear()
Definition: mxeventkm.h:102
__inline PVOID GetEvent()
Definition: mxeventkm.h:69
__inline VOID Set()
Definition: mxeventkm.h:91
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS Initialize(__in EVENT_TYPE Type, __in BOOLEAN InitialState)
Definition: mxeventkm.h:55
__inline LONG ReadState()
Definition: mxeventkm.h:135
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
#define _Acquires_lock_(lock)
#define _Releases_lock_(lock)
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define __drv_when(cond, annotes)
Definition: driverspecs.h:335
pPkgPnp m_DeviceInterfaceLock AcquireLock(pFxDriverGlobals)
pPkgPnp m_DeviceInterfaceLock ReleaseLock(pFxDriverGlobals)
DriverGlobals
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
@ FX_TYPE_WAIT_LOCK
Definition: fxtypes.h:76
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _When_(expr, annos)
Definition: ms_sal.h:254
#define CHECK_RETURN_IF_USER_MODE
Definition: mxmacros.h:26
#define KernelMode
Definition: asm.h:34
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE _In_ BOOLEAN InitialState
Definition: exfuncs.h:169
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
@ SynchronizationEvent
enum _EVENT_TYPE EVENT_TYPE
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
long LONG
Definition: pedump.c:60
static ULONG Timeout
Definition: ping.c:61
NTSTATUS EnterCRAndWaitAndLeave(VOID)
Definition: fxwaitlock.hpp:87
__drv_valueIs(==0;==258) _Acquires_lock_(_Global_critical_region_) NTSTATUS EnterCRAndWait(VOID)
Definition: fxwaitlock.hpp:68
FxCREvent * GetSelfPointer(VOID)
Definition: fxwaitlock.hpp:180
PVOID GetEvent(VOID)
Definition: fxwaitlock.hpp:172
LONG ReadState(VOID)
Definition: fxwaitlock.hpp:160
_Releases_lock_(_Global_critical_region_) VOID LeaveCR(VOID)
Definition: fxwaitlock.hpp:134
FxCREvent(__in EVENT_TYPE Type, __in BOOLEAN InitialState)
Definition: fxwaitlock.hpp:36
_Must_inspect_result_ NTSTATUS EnterCRAndWaitAndLeave(__in PLONGLONG Timeout)
Definition: fxwaitlock.hpp:122
VOID Set(VOID)
Definition: fxwaitlock.hpp:144
__drv_when(Timeout==NULL, __drv_valueIs(==0)) __drv_when(Timeout !
FxCREvent * operator&(VOID)
Definition: fxwaitlock.hpp:191
FxCREvent(__in BOOLEAN InitialState=FALSE)
Definition: fxwaitlock.hpp:17
VOID Clear(VOID)
Definition: fxwaitlock.hpp:152
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize(__in EVENT_TYPE Type, __in BOOLEAN InitialState)
Definition: fxwaitlock.hpp:60
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize(__in BOOLEAN InitialState=FALSE)
Definition: fxwaitlock.hpp:51
MxEvent m_Event
Definition: fxwaitlock.hpp:208
Definition: ps.c:97
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:717
@ Executive
Definition: ketypes.h:415