ReactOS  0.4.15-dev-3173-g40ee59d
fxsystemworkitem.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxSystemWorkItem.hpp
8 
9 Abstract:
10 
11  This implements an internal framework workitem that manages
12  cleanup.
13 
14 Author:
15 
16 
17 
18 Environment:
19 
20  Both kernel and user mode
21 
22 Revision 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)
40 typedef
41 VOID
42 EVT_SYSTEMWORKITEM(
44  );
45 
46 typedef EVT_SYSTEMWORKITEM FN_WDF_SYSTEMWORKITEM,*PFN_WDF_SYSTEMWORKITEM;
47 
49 
50 private:
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 
106 public:
107  static
109  NTSTATUS
110  _Create(
111  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
112  __in PVOID WdmObject,
114  );
115 
116  virtual
118  );
119 
120  virtual
122  NTSTATUS
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
140  MdWorkItem
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
169  WaitForExit(
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) {
195  m_RemoveEvent.Set();
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 
220 private:
222  __in PFX_DRIVER_GLOBALS FxDriverGlobals
223  );
224 
225  virtual
226  BOOLEAN
227  Dispose(
228  VOID
229  );
230 
232  NTSTATUS
233  Initialize(
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 
PFN_WDF_SYSTEMWORKITEM m_Callback
FxObject * pObject
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID WdmObject, __out FxSystemWorkItem **pObject)
virtual ~FxSystemWorkItem()
__inline MdWorkItem GetWorkItemPtr(VOID)
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:306
GLuint64EXT * result
Definition: glext.h:11304
FxSystemWorkItem(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
__inline MdWorkItem GetWorkItem()
Definition: mxworkitemkm.h:73
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
EVT_SYSTEMWORKITEM * PFN_WDF_SYSTEMWORKITEM
LONG NTSTATUS
Definition: precomp.h:26
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:290
FxCREvent m_WorkItemCompleted
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
IO_WORKITEM_ROUTINE MX_WORKITEM_ROUTINE
Definition: mxworkitemkm.h:26
_In_ PVOID Parameter
Definition: ldrtypes.h:241
virtual BOOLEAN Dispose(VOID)
VOID Set(VOID)
Definition: fxwaitlock.hpp:144
__inline BOOLEAN Enqueue(__in PFN_WDF_SYSTEMWORKITEM CallbackFunc, __in PVOID Parameter)
__inline BOOLEAN TryToEnqueue(__in PFN_WDF_SYSTEMWORKITEM CallbackFunc, __in PVOID Parameter)
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define __out
Definition: dbghelp.h:62
NTSTATUS EnterCRAndWaitAndLeave(VOID)
Definition: fxwaitlock.hpp:87
unsigned char BOOLEAN
EVT_SYSTEMWORKITEM FN_WDF_SYSTEMWORKITEM
__inline VOID DecrementWorkItemQueued()
#define __drv_sameIRQL
Definition: driverspecs.h:324
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN EnqueueWorker(__in PFN_WDF_SYSTEMWORKITEM Func, __in PVOID Parameter, __in BOOLEAN AssertIfAlreadyQueued)
#define InterlockedDecrement
Definition: armddk.h:52
_Function_class_(EVT_SYSTEMWORKITEM) __drv_maxIRQL(PASSIVE_LEVEL) __drv_maxFunctionIRQL(DISPATCH_LEVEL) __drv_sameIRQL typedef VOID EVT_SYSTEMWORKITEM(__in PVOID Parameter)
#define __inout
Definition: dbghelp.h:50
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define InterlockedIncrement
Definition: armddk.h:53
void(* Func)(int)
_Must_inspect_result_ NTSTATUS Initialize(__in PVOID WdmObject)
unsigned int ULONG
Definition: retypes.h:1
__inline VOID ReleaseWorkItemQueuedCountAndWait()
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
Definition: fxobject.cpp:255
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline VOID IncrementWorkItemQueued()
static MX_WORKITEM_ROUTINE _WorkItemThunk
#define __in
Definition: dbghelp.h:35
#define __drv_maxFunctionIRQL(irql)
Definition: driverspecs.h:289
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97