1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 ModuleName:
6 
7     MxEvent.h
8 
9 Abstract:
10 
11     Kernel mode implementation of event
12     class defined in MxEvent.h
13 
14 Author:
15 
16 
17 
18 Revision History:
19 
20 
21 
22 --*/
23 
24 #pragma once
25 
26 typedef KEVENT MdEvent;
27 
28 #include "mxevent.h"
29 
30 __inline
MxEvent()31 MxEvent::MxEvent()
32 {
33     //
34     // Make sure that m_Event is the first member. That way if someone passes
35     // address of MxEvent to Ke*Event functions, it would still work.
36     //
37     // If this statement causes compilation failure, check if you added a field
38     // before m_Event.
39     //
40     C_ASSERT(FIELD_OFFSET(MxEvent, m_Event) == 0);
41 
42     CLEAR_DBGFLAG_INITIALIZED;
43 }
44 
45 __inline
~MxEvent()46 MxEvent::~MxEvent()
47 {
48 }
49 
50 __inline
51 NTSTATUS
52 #ifdef _MSC_VER
53 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "_Must_inspect_result_ not needed in kernel mode as the function always succeeds");
54 #endif
Initialize(__in EVENT_TYPE Type,__in BOOLEAN InitialState)55 MxEvent::Initialize(
56     __in EVENT_TYPE Type,
57     __in BOOLEAN InitialState
58     )
59 {
60     KeInitializeEvent(&m_Event, Type, InitialState);
61 
62     SET_DBGFLAG_INITIALIZED;
63 
64     return STATUS_SUCCESS;
65 }
66 
67 __inline
68 PVOID
GetEvent()69 MxEvent::GetEvent(
70     )
71 {
72     ASSERT_DBGFLAG_INITIALIZED;
73 
74     return &m_Event;
75 }
76 
77 
78 __inline
79 VOID
SetWithIncrement(__in KPRIORITY Priority)80 MxEvent::SetWithIncrement(
81     __in KPRIORITY Priority
82     )
83 {
84     ASSERT_DBGFLAG_INITIALIZED;
85 
86     KeSetEvent(&m_Event, Priority, FALSE);
87 }
88 
89 __inline
90 VOID
Set()91 MxEvent::Set(
92     )
93 {
94     ASSERT_DBGFLAG_INITIALIZED;
95 
96     KeSetEvent(&m_Event, IO_NO_INCREMENT, FALSE);
97 }
98 
99 
100 __inline
101 VOID
Clear()102 MxEvent::Clear(
103     )
104 {
105     ASSERT_DBGFLAG_INITIALIZED;
106 
107     KeClearEvent(&m_Event);
108 }
109 
110 __drv_when(Timeout == NULL && Alertable == FALSE, __drv_valueIs(==0))
111 __drv_when(Timeout != NULL && Alertable == FALSE, __drv_valueIs(==0;==258))
112 __drv_when(Timeout != NULL || Alertable == TRUE, _Must_inspect_result_)
113 __inline
114 NTSTATUS
WaitFor(__in KWAIT_REASON WaitReason,__in KPROCESSOR_MODE WaitMode,__in BOOLEAN Alertable,__in_opt PLARGE_INTEGER Timeout)115 MxEvent::WaitFor(
116     __in     KWAIT_REASON  WaitReason,
117     __in     KPROCESSOR_MODE  WaitMode,
118     __in     BOOLEAN  Alertable,
119     __in_opt PLARGE_INTEGER  Timeout
120     )
121 {
122     ASSERT_DBGFLAG_INITIALIZED;
123 
124     return KeWaitForSingleObject(
125                     &m_Event,
126                     WaitReason,
127                     WaitMode,
128                     Alertable,
129                     Timeout
130                     );
131 }
132 
133 LONG
134 __inline
ReadState()135 MxEvent::ReadState(
136     )
137 {
138     ASSERT_DBGFLAG_INITIALIZED;
139 
140     return KeReadStateEvent(&m_Event);
141 }
142 
143 
144 __inline
145 VOID
Uninitialize()146 MxEvent::Uninitialize(
147     )
148 {
149     CLEAR_DBGFLAG_INITIALIZED;
150 }
151