ReactOS 0.4.15-dev-7924-g5949c20
mxeventum.h
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5ModuleName:
6
7 MxEventUm.h
8
9Abstract:
10
11 User mode implementation of event
12 class defined in MxEvent.h
13
14Author:
15
16
17
18Revision History:
19
20
21
22--*/
23
24#pragma once
25
26typedef struct {
28#if DBG
29 EVENT_TYPE Type; //tracked to allow ReadState only for notification events
30#endif
31} MdEvent;
32
33#include "DbgMacros.h"
34#include "MxEvent.h"
35
36__inline
38{
40
42}
43
44__inline
46{
47 //
48 // PLEASE NOTE: shared code must not rely of d'tor uninitializing the
49 // event. d'tor may not be invoked if the event is used in a structure
50 // which is allocated/deallocated using MxPoolAllocate/Free instead of
51 // new/delete
52 //
54}
55
57__inline
62 )
63{
66 BOOL bManualReset;
67
69 {
70 bManualReset = TRUE;
71 }
72 else
73 {
74 bManualReset = FALSE;
75 }
76
77 event = CreateEvent(
78 NULL,
79 bManualReset,
81 NULL
82 );
83
84 if (NULL == event) {
87 goto exit;
88 }
89
91
92#if DBG
93 m_Event.Type = Type;
94#endif
95
97
98exit:
99 return status;
100}
101
102__inline
103PVOID
105 )
106{
108
109 return m_Event.Event;
110}
111
112__inline
113VOID
115 )
116{
118
120}
121
122__inline
123VOID
126 )
127{
129
131
132 Set();
133}
134
135__inline
136VOID
138 )
139{
141
143}
144
146__inline
149 __in KWAIT_REASON WaitReason,
150 __in KPROCESSOR_MODE WaitMode,
153 )
154/*++
155
156Routine Description:
157 Waits for the event
158
159Arguments:
160 WaitReason - Unused (only there to match km definition)
161
162 WaitMode - Unuses (only there to match km definition)
163
164 Altertable - Whether the wait is alertable
165
166 Timout - Timeout in 100 ns units, MUST BE NEGATIVE
167 (negative implies relative timeout)
168
169Return Value:
170 Status corresponding to return value of WaitForSingleObjectEx
171
172 --*/
173{
175
176 DWORD retVal;
177
178 UNREFERENCED_PARAMETER(WaitReason);
179 UNREFERENCED_PARAMETER(WaitMode);
180
181 LONGLONG relativeTimeOut = 0;
182 LONGLONG timeoutInMs = 0;
183 DWORD dwTimeout = 0;
184
185 if (NULL != Timeout)
186 {
187 //
188 // Make sure that timeout is 0 or -ve (which implies relative timeout)
189 //
190 if (Timeout->QuadPart > 0)
191 {
193 "Absolute wait not supported in user mode",
194 FALSE
195 );
196
198 }
199
200 //
201 // Remove the -ve sign
202 //
203 if (Timeout->QuadPart < 0)
204 {
205 relativeTimeOut = -1 * Timeout->QuadPart;
206 }
207
208 //
209 // Convert from 100ns units to milliseconds
210 //
211 timeoutInMs = (relativeTimeOut / (10 * 1000));
212
213 if (timeoutInMs > ULONG_MAX)
214 {
215 Mx::MxAssertMsg("Timeout too large", FALSE);
216
218 }
219 else
220 {
221 dwTimeout = (DWORD) timeoutInMs;
222 }
223 }
224
225 retVal = WaitForSingleObjectEx(
229 );
230
231 switch(retVal)
232 {
233 case WAIT_ABANDONED:
234 return STATUS_ABANDONED;
235 case WAIT_OBJECT_0:
236 return STATUS_SUCCESS;
237 case WAIT_TIMEOUT:
238 return STATUS_TIMEOUT;
239 case WAIT_FAILED:
240 {
242 return WinErrorToNtStatus(err);
243 }
244 default:
245 {
246 //
247 // We shoudn't get here
248 //
250 return STATUS_UNSUCCESSFUL;
251 }
252 }
253}
254
255LONG
256__inline
258 )
259{
261
262#if DBG
264#endif
265
268 0
269 )) {
270 return 1;
271 }
272 else {
273 return 0;
274 }
275}
276
277
278__inline
279VOID
281 )
282{
283 if (NULL != m_Event.Event) {
286 }
287
289}
unsigned char BOOLEAN
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
__inline VOID SetWithIncrement(__in KPRIORITY Priority)
Definition: mxeventkm.h:80
_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 VOID Uninitialize()
Definition: mxeventkm.h:146
__inline ~MxEvent()
Definition: mxeventkm.h:46
__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 MxEvent()
Definition: mxeventkm.h:31
__inline LONG ReadState()
Definition: mxeventkm.h:135
MdEvent m_Event
Definition: mxevent.h:36
static __inline VOID MxAssertMsg(__in LPSTR Message, __in BOOLEAN Condition)
Definition: mxgeneralkm.h:176
static __inline VOID MxAssert(__in BOOLEAN Condition)
Definition: mxgeneralkm.h:165
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define ASSERT_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:58
#define SET_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:59
#define CLEAR_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:60
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
LONG KPRIORITY
Definition: compat.h:803
#define INFINITE
Definition: serial.h:102
#define __drv_when(cond, annotes)
Definition: driverspecs.h:335
NTSTATUS WinErrorToNtStatus(__in ULONG WinError)
Definition: errtostatus.cpp:60
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _cl_event * event
Definition: glext.h:7739
#define ULONG_MAX
Definition: limits.h:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:453
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE _In_ BOOLEAN InitialState
Definition: exfuncs.h:169
#define DWORD
Definition: nt_native.h:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ NotificationEvent
enum _EVENT_TYPE EVENT_TYPE
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_ABANDONED
Definition: ntstatus.h:75
long LONG
Definition: pedump.c:60
static ULONG Timeout
Definition: ping.c:61
#define err(...)
#define exit(n)
Definition: config.h:202
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE Event
Definition: mxeventum.h:27
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
int64_t LONGLONG
Definition: typedefs.h:68
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:655
#define WAIT_ABANDONED
Definition: winbase.h:412
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateEvent
Definition: winbase.h:3748
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WAIT_FAILED
Definition: winbase.h:413
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD dwTimeout
Definition: wincrypt.h:6081
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
enum _KWAIT_REASON KWAIT_REASON