ReactOS 0.4.15-dev-8417-gb6b82fe
fxsystemworkitem.hpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxSystemWorkItem.hpp
8
9Abstract:
10
11 This implements an internal framework workitem that manages
12 cleanup.
13
14Author:
15
16
17
18Environment:
19
20 Both kernel and user mode
21
22Revision History:
23
24
25--*/
26
27#ifndef _FXSYSTEMWORKITEM_H
28#define _FXSYSTEMWORKITEM_H
29
30//
31// This class provides a common place for code to deal with
32// cleanup and synchronization issues of workitems utilized
33// internally by the framework
34//
35
36_Function_class_(EVT_SYSTEMWORKITEM)
40typedef
41VOID
42EVT_SYSTEMWORKITEM(
44 );
45
47
49
50private:
51
52 // Ensures only one of either Delete or Cleanup runs down the object
54
55 //
56 // If this is set, a WorkItem has been enqueued
57 //
59
60 //
61 // The workitem we use
62 //
64
65 //
66 // The callback function
67 //
69
71
72 //
73 // This event is signaled when the workitem is done processing
74 // an Enqueue request.
75 //
77
78 //
79 // This count is used to prevent the object from being deleted if
80 // one worker thread is preempted right after we drop the lock to call
81 // the client callback and another workitem gets queued and runs
82 // to completion and signals the event.
83 //
85
86 //
87 // We will keep a count of workitems queued and wait for
88 // all the workitems to run to completion before allowing the
89 // dispose to complete. Since this object is also used in running
90 // down the dispose list during driver unload, this run-down
91 // protection is required to make sure that the unload after deleting
92 // this object doesn't run ahead of the dispose worker thread.
93 //
95
96 //
97 // This event will be signed when the above count drops to zero.
98 // The initial value of the count is biased to zero to provide
99 // remlock semantics. This event is configured to be a synchronziation
100 // event because we know for sure the only thread that's going to
101 // wait on this event is the one that's going to call Dispose and
102 // after that the object will be destroyed.
103 //
105
106public:
107 static
110 _Create(
111 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
112 __in PVOID WdmObject,
114 );
115
116 virtual
118 );
119
120 virtual
125 )
126 {
127 switch (Params->Type) {
129 *Params->Object = (FxSystemWorkItem*) this;
130 break;
131
132 default:
133 return FxNonPagedObject::QueryInterface(Params); // __super call
134 }
135
136 return STATUS_SUCCESS;
137 }
138
139 __inline
142 VOID
143 )
144 {
145 return m_WorkItem.GetWorkItem();
146 }
147
148 __inline
149 BOOLEAN
151 __in PFN_WDF_SYSTEMWORKITEM CallbackFunc,
153 )
154 {
155 return EnqueueWorker(CallbackFunc, Parameter, TRUE);
156 }
157
158 __inline
159 BOOLEAN
161 __in PFN_WDF_SYSTEMWORKITEM CallbackFunc,
163 )
164 {
165 return EnqueueWorker(CallbackFunc, Parameter, FALSE);
166 }
167
168 VOID
170 VOID
171 );
172
173 __inline
174 VOID
176 )
177 {
179
181 }
182
183 __inline
184 VOID
186 )
187 {
188 LONG result;
189
191
193
194 if (result == 0) {
196 }
197 }
198
199 __inline
200 VOID
202 )
203 {
205
206 //
207 // Drop the bias count to indicate the object is being removed.
208 //
210
214
216 }
217
219
220private:
222 __in PFX_DRIVER_GLOBALS FxDriverGlobals
223 );
224
225 virtual
226 BOOLEAN
227 Dispose(
228 VOID
229 );
230
234 __in PVOID WdmObject
235 );
236
237 VOID
239 );
240
241 static
244
245 BOOLEAN
249 __in BOOLEAN AssertIfAlreadyQueued
250 );
251};
252
253#endif // _FXSYSTEMWORKITEM_H
254
unsigned char BOOLEAN
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
Definition: fxobject.cpp:255
FxCREvent m_WorkItemCompleted
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID WdmObject, __out FxSystemWorkItem **pObject)
__inline VOID ReleaseWorkItemQueuedCountAndWait()
__inline VOID IncrementWorkItemQueued()
__inline MdWorkItem GetWorkItemPtr(VOID)
PFN_WDF_SYSTEMWORKITEM m_Callback
virtual BOOLEAN Dispose(VOID)
__inline VOID DecrementWorkItemQueued()
__inline BOOLEAN TryToEnqueue(__in PFN_WDF_SYSTEMWORKITEM CallbackFunc, __in PVOID Parameter)
BOOLEAN EnqueueWorker(__in PFN_WDF_SYSTEMWORKITEM Func, __in PVOID Parameter, __in BOOLEAN AssertIfAlreadyQueued)
__inline BOOLEAN Enqueue(__in PFN_WDF_SYSTEMWORKITEM CallbackFunc, __in PVOID Parameter)
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
static MX_WORKITEM_ROUTINE _WorkItemThunk
virtual ~FxSystemWorkItem()
__inline MdWorkItem GetWorkItem()
Definition: mxworkitemkm.h:73
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define __out
Definition: dbghelp.h:62
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define __drv_maxFunctionIRQL(irql)
Definition: driverspecs.h:290
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define __drv_sameIRQL
Definition: driverspecs.h:325
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FxObject * pObject
EVT_SYSTEMWORKITEM FN_WDF_SYSTEMWORKITEM
EVT_SYSTEMWORKITEM * PFN_WDF_SYSTEMWORKITEM
@ FX_TYPE_SYSTEMWORKITEM
Definition: fxtypes.h:84
GLuint64EXT * result
Definition: glext.h:11304
#define ASSERT(a)
Definition: mode.c:44
#define _Function_class_(x)
Definition: ms_sal.h:2946
#define _Must_inspect_result_
Definition: ms_sal.h:558
IO_WORKITEM_ROUTINE MX_WORKITEM_ROUTINE
Definition: mxworkitemkm.h:26
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
long LONG
Definition: pedump.c:60
void(* Func)(int)
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS EnterCRAndWaitAndLeave(VOID)
Definition: fxwaitlock.hpp:87
VOID Set(VOID)
Definition: fxwaitlock.hpp:144
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336
static void Initialize()
Definition: xlate.c:212