ReactOS  0.4.15-dev-3331-g8ebe441
FxWorkItem Class Reference

#include <fxworkitem.hpp>

Inheritance diagram for FxWorkItem:
Collaboration diagram for FxWorkItem:

Public Member Functions

 FxWorkItem (__in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
virtual ~FxWorkItem ()
 
MdWorkItem GetWorkItemPtr ()
 
_Must_inspect_result_ NTSTATUS Initialize (__in PWDF_OBJECT_ATTRIBUTES Attributes, __in PWDF_WORKITEM_CONFIG Config, __in FxObject *ParentObject, __out WDFWORKITEM *WorkItem)
 
virtual BOOLEAN Dispose (VOID)
 
VOID Enqueue ()
 
WDFOBJECT GetAssociatedObject ()
 
WDFWORKITEM GetHandle (VOID)
 
VOID FlushAndWait (VOID)
 
- Public Member Functions inherited from FxNonPagedObject
 FxNonPagedObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
 FxNonPagedObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType ObjectType)
 
virtual ~FxNonPagedObject (VOID)
 
 _Acquires_lock_ (this->m_NPLock.m_Lock) __drv_maxIRQL(DISPATCH_LEVEL) __drv_setsIRQL(DISPATCH_LEVEL) VOID Lock(__out __drv_deref(__drv_savesIRQL) PKIRQL PreviousIrql)
 
 _Releases_lock_ (this->m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) __inline VOID Unlock(__in __drv_restoresIRQL KIRQL PreviousIrql)
 
 _Acquires_lock_ (this->m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) VOID LockAtDispatch(VOID)
 
 _Requires_lock_held_ (this->m_NPLock.m_Lock) _Releases_lock_(this -> m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) __inline VOID UnlockFromDispatch(VOID)
 
- Public Member Functions inherited from FxObject
PVOID GetCOMWrapper ()
 
void SetCOMWrapper (__drv_aliasesMem PVOID Wrapper)
 
 FxObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
virtual ~FxObject (VOID)
 
PVOID __inline operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType Type)
 
PVOID __inline operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in USHORT ExtraSize=0)
 
VOID operator delete (__in PVOID Memory)
 
VOID SetNoContextHeader (VOID)
 
PVOID __inline GetObjectHandle (VOID)
 
__inline FxContextHeaderGetContextHeader (VOID)
 
__inline PFX_DRIVER_GLOBALS GetDriverGlobals (VOID)
 
WDFTYPE GetType (VOID)
 
USHORT GetObjectSize (VOID)
 
LONG GetRefCnt (VOID)
 
FxTagTrackerGetTagTracker (VOID)
 
CfxDeviceGetDevice (VOID)
 
CfxDeviceBaseGetDeviceBase (VOID)
 
VOID SetDeviceBase (__in CfxDeviceBase *DeviceBase)
 
__inline VOID CallCleanup (VOID)
 
ULONG __inline AddRef (__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG Release (__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG AddRefOverride (__in WDFOBJECT_OFFSET Offset, __in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG ReleaseOverride (__in WDFOBJECT_OFFSET Offset, __in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual _Must_inspect_result_ NTSTATUS QueryInterface (__in FxQueryInterfaceParams *Params)
 
VOID MarkTraceState (VOID)
 
BOOLEAN __inline IsTraceState (VOID)
 
VOID __inline TraceDroppedEvent (__in FxObjectDroppedEvent Event)
 
VOID MarkPassiveDispose (__in FxObjectLockState State=ObjectLock)
 
VOID MarkPassiveCallbacks (__in FxObjectLockState State=ObjectLock)
 
VOID MarkForceDisposeThread (__in FxObjectLockState State=ObjectLock)
 
BOOLEAN IsPassiveCallbacks (__in BOOLEAN AcquireLock=TRUE)
 
BOOLEAN IsPassiveDispose (__in BOOLEAN AcquireLock=TRUE)
 
BOOLEAN IsForceDisposeThread (__in BOOLEAN AcquireLock=TRUE)
 
VOID MarkCommitted (VOID)
 
BOOLEAN IsCommitted (VOID)
 
VOID MarkDisposeOverride (__in FxObjectLockState State=ObjectLock)
 
VOID MarkNoDeleteDDI (__in FxObjectLockState State=ObjectLock)
 
BOOLEAN IsNoDeleteDDI (VOID)
 
_Must_inspect_result_ NTSTATUS Commit (__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
 
VOID DeleteFromFailedCreate (VOID)
 
VOID ClearEvtCallbacks (VOID)
 
BOOLEAN EarlyDispose (VOID)
 
virtual VOID DeleteObject (VOID)
 
_Must_inspect_result_ NTSTATUS AssignParentObject (__in FxObject *ParentObject)
 
_Must_inspect_result_ NTSTATUS AddContext (__in FxContextHeader *Header, __in PVOID *Context, __in PWDF_OBJECT_ATTRIBUTES Attributes)
 
_Must_inspect_result_ NTSTATUS RemoveParentAssignment (VOID)
 
_Must_inspect_result_ FxObjectGetParentObjectReferenced (__in PVOID Tag)
 
BOOLEAN IsDisposed (VOID)
 

Static Public Member Functions

static _Must_inspect_result_ NTSTATUS _Create (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_WORKITEM_CONFIG Config, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObject *ParentObject, __out WDFWORKITEM *WorkItem)
 
- Static Public Member Functions inherited from FxObject
static FxObject_FromDisposeEntry (__in PSINGLE_LIST_ENTRY Entry)
 
static FxObject_GetObjectFromHandle (__in WDFOBJECT Handle, __inout PWDFOBJECT_OFFSET ObjectOffset)
 
static PVOID __inline _ToHandle (__in FxObject *Object)
 
static VOID __inline _ReferenceActual (__in WDFOBJECT Object, __in_opt PVOID Tag, __in LONG Line, __in PSTR File)
 
static VOID __inline _DereferenceActual (__in WDFOBJECT Object, __in_opt PVOID Tag, __in LONG Line, __in PSTR File)
 
static PVOID _GetDebugBase (__in FxObject *Object)
 
static PFX_POOL_HEADER _CleanupPointer (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Object)
 
static _Must_inspect_result_ NTSTATUS _GetEffectiveLock (__in FxObject *Object, __in_opt IFxHasCallbacks *Callbacks, __in BOOLEAN AutomaticLocking, __in BOOLEAN PassiveCallbacks, __out FxCallbackLock **CallbackLock, __out_opt FxObject **CallbackLockObject)
 
static _Must_inspect_result_ NTSTATUS _ObjectQuery (_In_ FxObject *Object, _In_ CONST GUID *Guid, _In_ ULONG QueryBufferLength, _Out_writes_bytes_(QueryBufferLength) PVOID QueryBuffer)
 

Private Member Functions

VOID FlushAndRundown ()
 
VOID WorkItemHandler ()
 
VOID WaitForSignal (VOID)
 

Private Attributes

MxWorkItem m_WorkItem
 
BOOLEAN m_RunningDown
 
BOOLEAN m_Enqueued
 
ULONG m_WorkItemRunningCount
 
FxObjectm_Object
 
FxCallbackLockm_CallbackLock
 
FxObjectm_CallbackLockObject
 
PFN_WDF_WORKITEM m_Callback
 
FxCREvent m_WorkItemCompleted
 
MxThread m_WorkItemThread
 

Static Private Attributes

static MX_WORKITEM_ROUTINE WorkItemThunk
 

Additional Inherited Members

- Protected Member Functions inherited from FxObject
 FxObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType ObjectType)
 
FxObjectDebugExtensionGetDebugExtension (VOID)
 
BOOLEAN IsDebug (VOID)
 
VOID AllocateTagTracker (__in WDFTYPE Type)
 
virtual VOID SelfDestruct (VOID)
 
PVOID __inline GetObjectHandleUnchecked (VOID)
 
VOID __inline DestroyChildren (VOID)
 
VOID DeleteEarlyDisposedObject (VOID)
 
- Static Protected Member Functions inherited from FxObject
static PVOID _GetBase (__in FxObject *Object)
 
- Protected Attributes inherited from FxObject
union {
   CfxDeviceBase *   m_DeviceBase
 
   CfxDevice *   m_Device
 
}; 
 

Detailed Description

Definition at line 47 of file fxworkitem.hpp.

Constructor & Destructor Documentation

◆ FxWorkItem()

FxWorkItem::FxWorkItem ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals)

Definition at line 43 of file fxworkitem.cpp.

45  :
46  FxNonPagedObject(FX_TYPE_WORKITEM, sizeof(FxWorkItem), FxDriverGlobals),
48 {
49  m_Object = NULL;
50  m_Callback = NULL;
54  m_Enqueued = FALSE;
57 
58  //
59  // All operations on a workitem are PASSIVE_LEVEL so ensure that any Dispose
60  // and Destroy callbacks to the driver are as well.
61  //
63 
65 }
BOOLEAN m_RunningDown
Definition: fxworkitem.hpp:56
FxNonPagedObject(__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
BOOLEAN m_Enqueued
Definition: fxworkitem.hpp:61
#define TRUE
Definition: types.h:120
MxThread m_WorkItemThread
Definition: fxworkitem.hpp:105
FxCallbackLock * m_CallbackLock
Definition: fxworkitem.hpp:81
PFN_WDF_WORKITEM m_Callback
Definition: fxworkitem.hpp:92
#define FALSE
Definition: types.h:117
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
FxCREvent m_WorkItemCompleted
Definition: fxworkitem.hpp:98
VOID MarkPassiveCallbacks(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:972
FxObject * m_CallbackLockObject
Definition: fxworkitem.hpp:87
ULONG m_WorkItemRunningCount
Definition: fxworkitem.hpp:69
FxObject * m_Object
Definition: fxworkitem.hpp:75
#define NULL
Definition: types.h:112

Referenced by _Create().

◆ ~FxWorkItem()

FxWorkItem::~FxWorkItem ( )
virtual

Definition at line 68 of file fxworkitem.cpp.

71 {
73 
75 
76  //
77  // If this hits, it's because someone destroyed the WORKITEM by
78  // removing too many references by mistake without calling WdfObjectDelete
79  //
80  if (m_RunningDown == FALSE && m_Callback != NULL) {
83  "WDFWORKITEM %p destroyed without calling WdfObjectDelete, or by "
84  "Framework processing DeviceRemove. Possible reference count "
85  "problem?", GetObjectHandleUnchecked());
87  }
88 
89  // Release our parent object reference
90  if (m_Object != NULL) {
91  m_Object->RELEASE(this);
92  m_Object = NULL;
93  }
94 
95  // Free the workitem
96  if (m_WorkItem.GetWorkItem() != NULL) {
97  m_WorkItem.Free();
98  //m_WorkItem = NULL;
99  }
100 
101  ASSERT(m_Enqueued == FALSE);
103 
104  return;
105 }
BOOLEAN m_RunningDown
Definition: fxworkitem.hpp:56
BOOLEAN m_Enqueued
Definition: fxworkitem.hpp:61
__inline MdWorkItem GetWorkItem()
Definition: mxworkitemkm.h:73
PFN_WDF_WORKITEM m_Callback
Definition: fxworkitem.hpp:92
MxWorkItem m_WorkItem
Definition: fxworkitem.hpp:53
#define FALSE
Definition: types.h:117
#define TRACINGDEVICE
Definition: dbgtrace.h:58
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define ASSERT(a)
Definition: mode.c:44
ULONG m_WorkItemRunningCount
Definition: fxworkitem.hpp:69
PVOID __inline GetObjectHandleUnchecked(VOID)
Definition: fxobject.hpp:446
static const WCHAR L[]
Definition: oid.c:1250
FxObject * m_Object
Definition: fxworkitem.hpp:75
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
__inline VOID Free()
Definition: mxworkitemkm.h:90
FxVerifierDbgBreakPoint(pFxDriverGlobals)

Member Function Documentation

◆ _Create()

return FxWorkItem::_Create ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PWDF_WORKITEM_CONFIG  Config,
__in PWDF_OBJECT_ATTRIBUTES  Attributes,
__in FxObject ParentObject,
__out WDFWORKITEM *  WorkItem 
)
static

Definition at line 109 of file fxworkitem.cpp.

116 {
119 
120  pFxWorkItem = new(FxDriverGlobals, Attributes) FxWorkItem(FxDriverGlobals);
121 
122  if (pFxWorkItem == NULL) {
124  }
125 
127  Attributes,
128  Config,
129  ParentObject,
130  WorkItem
131  );
132 
133  if (!NT_SUCCESS(status)) {
135  }
136 
137  return status;
138 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
FxWorkItem(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxworkitem.cpp:43
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ NTSTATUS Initialize(__in PWDF_OBJECT_ATTRIBUTES Attributes, __in PWDF_WORKITEM_CONFIG Config, __in FxObject *ParentObject, __out WDFWORKITEM *WorkItem)
Definition: fxworkitem.cpp:142
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
#define NULL
Definition: types.h:112
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:110
FxWorkItem * pFxWorkItem
static SERVICE_STATUS status
Definition: service.c:31
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97

◆ Dispose()

BOOLEAN FxWorkItem::Dispose ( VOID  )
virtual

Reimplemented from FxObject.

Definition at line 479 of file fxworkitem.cpp.

495 {
496  KIRQL irql;
497 
498  Lock(&irql);
500  Unlock(irql);
501 
502  FlushAndRundown();
503 
504  return TRUE;
505 }
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
BOOLEAN m_RunningDown
Definition: fxworkitem.hpp:56
VOID FlushAndRundown()
Definition: fxworkitem.cpp:448
#define TRUE
Definition: types.h:120
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124

◆ Enqueue()

VOID FxWorkItem::Enqueue ( )

Definition at line 288 of file fxworkitem.cpp.

291 {
293  KIRQL irql;
294  BOOLEAN enqueue;
295 
297  enqueue = FALSE;
298 
299  Lock(&irql);
300 
301  if (m_Enqueued) {
304  "Previously queued WDFWORKITEM 0x%p is already pending. "
305  "Ignoring the request to queue again", GetHandle());
306  }
307  else if (m_RunningDown) {
309  "WDFWORKITEM 0x%p is already deleted", GetHandle());
311  }
312  else {
314 
315  m_Enqueued = TRUE;
316 
317  //
318  // We are going to enqueue the work item. Reference this FxWorkItem
319  // object and Globals while they are outstanding.
320  // These will be released when the workitem completes.
321  //
324 
325  enqueue = TRUE;
326  }
327 
328  Unlock(irql);
329 
330  if (enqueue) {
332  }
333 
334  return;
335 }
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
static MX_WORKITEM_ROUTINE WorkItemThunk
Definition: fxworkitem.hpp:216
BOOLEAN m_RunningDown
Definition: fxworkitem.hpp:56
BOOLEAN m_Enqueued
Definition: fxworkitem.hpp:61
#define TRUE
Definition: types.h:120
KIRQL irql
Definition: wave.h:1
WDFWORKITEM GetHandle(VOID)
Definition: fxworkitem.hpp:193
UCHAR KIRQL
Definition: env_spec_w32.h:591
MxWorkItem m_WorkItem
Definition: fxworkitem.hpp:53
#define FALSE
Definition: types.h:117
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define ADDREF(_tag)
Definition: fxobject.hpp:49
unsigned char BOOLEAN
FxCREvent m_WorkItemCompleted
Definition: fxworkitem.hpp:98
#define TRACINGDEVICE
Definition: dbgtrace.h:58
PFX_DRIVER_GLOBALS pFxDriverGlobals
VOID Clear(VOID)
Definition: fxwaitlock.hpp:152
VOID Enqueue()
Definition: fxworkitem.cpp:288
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
FxVerifierDbgBreakPoint(pFxDriverGlobals)

◆ FlushAndRundown()

VOID FxWorkItem::FlushAndRundown ( )
private

Definition at line 448 of file fxworkitem.cpp.

451 {
452  FxObject* pObject;
453 
454  //
455  // Wait for any outstanding workitem to complete if the workitem is not
456  // deleted from within the workitem callback to avoid deadlock.
457  //
459  WaitForSignal();
460  }
461 
462  //
463  // Release our reference count to the associated parent object if present
464  //
465  if (m_Object != NULL) {
466  pObject = m_Object;
467  m_Object = NULL;
468 
469  pObject->RELEASE(this);
470  }
471 
472  //
473  // Perform our final release to ourselves, destroying the FxWorkItem
474  //
475  RELEASE(this);
476 }
FxObject * pObject
VOID WaitForSignal(VOID)
Definition: fxworkitem.cpp:534
MxThread m_WorkItemThread
Definition: fxworkitem.hpp:105
#define RELEASE(_tag)
Definition: fxobject.hpp:50
FxObject * m_Object
Definition: fxworkitem.hpp:75
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
#define NULL
Definition: types.h:112

Referenced by Dispose().

◆ FlushAndWait()

VOID FxWorkItem::FlushAndWait ( VOID  )

Definition at line 508 of file fxworkitem.cpp.

509 {
511 
513 
516  "Calling WdfWorkItemFlush from within the WDFWORKITEM "
517  "%p callback will lead to deadlock, PRKTHREAD %p",
520  return;
521  }
522 
523  //
524  // Wait for any outstanding workitem to complete.
525  // The event is only set upon return from the callback
526  // into the driver *and* the driver did not re-queue
527  // the workitem. See similar comment in WorkItemHandler().
528  //
529  WaitForSignal();
530  return;
531 }
VOID WaitForSignal(VOID)
Definition: fxworkitem.cpp:534
MxThread m_WorkItemThread
Definition: fxworkitem.hpp:105
WDFWORKITEM GetHandle(VOID)
Definition: fxworkitem.hpp:193
#define TRACINGDEVICE
Definition: dbgtrace.h:58
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxVerifierDbgBreakPoint(pFxDriverGlobals)

◆ GetAssociatedObject()

WDFOBJECT FxWorkItem::GetAssociatedObject ( )
inline

Definition at line 181 of file fxworkitem.hpp.

183  {
184  if( m_Object != NULL ) {
185  return m_Object->GetObjectHandle();
186  }
187  else {
188  return NULL;
189  }
190  }
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
FxObject * m_Object
Definition: fxworkitem.hpp:75
#define NULL
Definition: types.h:112

◆ GetHandle()

WDFWORKITEM FxWorkItem::GetHandle ( VOID  )
inline

Definition at line 193 of file fxworkitem.hpp.

196  {
197  return (WDFWORKITEM) GetObjectHandle();
198  }
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603

Referenced by Enqueue(), FlushAndWait(), WaitForSignal(), and WorkItemHandler().

◆ GetWorkItemPtr()

MdWorkItem FxWorkItem::GetWorkItemPtr ( )
inline

Definition at line 143 of file fxworkitem.hpp.

143  {
144  return m_WorkItem.GetWorkItem();
145  }
__inline MdWorkItem GetWorkItem()
Definition: mxworkitemkm.h:73
MxWorkItem m_WorkItem
Definition: fxworkitem.hpp:53

◆ Initialize()

_Must_inspect_result_ NTSTATUS FxWorkItem::Initialize ( __in PWDF_OBJECT_ATTRIBUTES  Attributes,
__in PWDF_WORKITEM_CONFIG  Config,
__in FxObject ParentObject,
__out WDFWORKITEM *  WorkItem 
)

Definition at line 142 of file fxworkitem.cpp.

148 {
150  IFxHasCallbacks* pCallbacks;
152 
154 
155 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
157  if(!NT_SUCCESS(status)) {
159  "Could not initialize m_WorkItemCompleted event "
160  "%!STATUS!", status);
161  return status;
162  }
163 #endif
164 
165  ASSERT(Config->EvtWorkItemFunc != NULL);
166 
167  // Set users callback function
168  m_Callback = Config->EvtWorkItemFunc;
169 
170  //
171  // As long as we are associated, the parent object holds a reference
172  // count on the WDFWORKITEM.
173  //
174  // This reference must be taken early before we return any failure,
175  // since Dispose() expects this extra reference, and Dispose() will
176  // be called even if we return a failure status right now.
177  //
178  ADDREF(this);
179 
180  //
181  // WorkItems can be parented by, and optionally serialize with an FxDevice or an FxQueue
182  //
183  m_DeviceBase = FxDeviceBase::_SearchForDevice(ParentObject, &pCallbacks);
184 
185  if (m_DeviceBase == NULL) {
187  }
188 
189  //
190  // Determine if it's an FxDevice, or FxIoQueue and get the
191  // CallbackSpinLock pointer for it.
192  //
194  ParentObject,
195  pCallbacks,
196  Config->AutomaticSerialization,
197  TRUE,
200  );
201 
202  if (!NT_SUCCESS(status)) {
204 
205 
206 
207 
208 
209 
212  "ParentObject %p cannot automatically synchronize callbacks "
213  "with a WorkItem since it is not configured for passive level "
214  "callback constraints. Use a WDFDPC instead or set "
215  "AutomaticSerialization to FALSE."
216  "%!STATUS!", Attributes->ParentObject, status);
217  }
218 
219  return status;
220  }
221 
222  //
223  // Allocate the PIO_WORKITEM we will re-use
224  //
225 #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
227 #elif (FX_CORE_MODE == FX_CORE_USER_MODE)
230  (PVOID)&m_Device->GetDriver()->GetDriverObject()->ThreadPoolEnv);
231 #endif
232  if (m_WorkItem.GetWorkItem() == NULL) {
236  "Could not allocate IoWorkItem, %!STATUS!", status);
237  return status;
238  }
239 
240  //
241  // We automatically synchronize with and reference count
242  // the lifetime of the framework object to prevent any WORKITEM races
243  // that can access the object while it is going away.
244  //
245 
246  //
247  // The caller supplied object is the object the caller wants the
248  // WorkItem to be associated with, and the framework must ensure this
249  // object remains live until the WorkItem object is destroyed. Otherwise,
250  // it could access either object context memory, or an object API
251  // on a freed object.
252  //
253  // Due to the locking model of the framework, the lock may actually
254  // be owned by a higher level object as well. This is the lockObject
255  // returned. As long as we are a child of this object, the lockObject
256  // does not need to be dereferenced since it will notify us of Cleanup
257  // before it goes away.
258  //
259 
260  //
261  // Associate the FxWorkItem with the object. When this object Cleans up, it
262  // will notify our Cleanup function as well.
263  //
264 
265  //
266  // Add a reference to the parent object we are associated with.
267  // We will be notified of Cleanup to release this reference.
268  //
269  ParentObject->ADDREF(this);
270 
271  // Save the ptr to the object the WorkItem is associated with
272  m_Object = ParentObject;
273 
274  //
275  // Attributes->ParentObject is the same as ParentObject. Since we already
276  // converted it to an object, use that.
277  //
278  status = Commit(Attributes, (WDFOBJECT*)WorkItem, ParentObject);
279 
280  if (!NT_SUCCESS(status)) {
281  return status;
282  }
283 
284  return status;
285 }
CfxDevice * m_Device
Definition: fxobject.hpp:329
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize(__in BOOLEAN InitialState=FALSE)
Definition: fxwaitlock.hpp:51
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
static _Must_inspect_result_ NTSTATUS _GetEffectiveLock(__in FxObject *Object, __in_opt IFxHasCallbacks *Callbacks, __in BOOLEAN AutomaticLocking, __in BOOLEAN PassiveCallbacks, __out FxCallbackLock **CallbackLock, __out_opt FxObject **CallbackLockObject)
Definition: fxobject.cpp:1044
__inline MdWorkItem GetWorkItem()
Definition: mxworkitemkm.h:73
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
FxCallbackLock * m_CallbackLock
Definition: fxworkitem.hpp:81
PFN_WDF_WORKITEM m_Callback
Definition: fxworkitem.hpp:92
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
MxWorkItem m_WorkItem
Definition: fxworkitem.hpp:53
#define ADDREF(_tag)
Definition: fxobject.hpp:49
#define STATUS_WDF_INCOMPATIBLE_EXECUTION_LEVEL
Definition: wdfstatus.h:198
_Must_inspect_result_ __inline NTSTATUS Allocate(__in MdDeviceObject DeviceObject, __in_opt PVOID ThreadPoolEnv=NULL)
Definition: mxworkitemkm.h:41
void * PVOID
Definition: retypes.h:9
FxCREvent m_WorkItemCompleted
Definition: fxworkitem.hpp:98
#define TRACINGDEVICE
Definition: dbgtrace.h:58
FxObject * m_CallbackLockObject
Definition: fxworkitem.hpp:87
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
__inline FxDriver * GetDriver(VOID)
Definition: fxdevice.hpp:164
CfxDeviceBase * m_DeviceBase
Definition: fxobject.hpp:328
FxObject * m_Object
Definition: fxworkitem.hpp:75
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline MdDriverObject GetDriverObject(VOID)
Definition: fxdriver.hpp:252
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:110
static SERVICE_STATUS status
Definition: service.c:31
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97

Referenced by _Create().

◆ WaitForSignal()

VOID FxWorkItem::WaitForSignal ( VOID  )
private

Definition at line 534 of file fxworkitem.cpp.

537 {
538  LARGE_INTEGER timeOut;
540 
542 
543  timeOut.QuadPart = WDF_REL_TIMEOUT_IN_SEC(60);
544 
545  do {
547  if (status == STATUS_TIMEOUT) {
548  DbgPrint("Thread 0x%p is waiting on WDFWORKITEM 0x%p\n",
550  GetHandle());
551  }
552  else {
554  break;
555  }
556  } WHILE(TRUE);
557 
558 
560  return;
561 }
#define DbgPrint
Definition: hal.h:12
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
WDFWORKITEM GetHandle(VOID)
Definition: fxworkitem.hpp:193
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
NTSTATUS EnterCRAndWaitAndLeave(VOID)
Definition: fxwaitlock.hpp:87
FxCREvent m_WorkItemCompleted
Definition: fxworkitem.hpp:98
#define WHILE(constant)
Definition: fxmacros.hpp:226
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static __inline KIRQL MxGetCurrentIrql()
Definition: mxgeneralkm.h:86
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
static __inline MdEThread GetCurrentEThread()
Definition: mxgeneralkm.h:69
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:114
Definition: ps.c:97

Referenced by FlushAndRundown(), and FlushAndWait().

◆ WorkItemHandler()

VOID FxWorkItem::WorkItemHandler ( )
private

Definition at line 338 of file fxworkitem.cpp.

341 {
342  KIRQL irql;
343 
345 
346  Lock(&irql);
347 
348  //
349  // Mark the workitem as no longer enqueued and completed
350  //
351  // The handler is allowed to re-enqueue, so mark it before the callback
352  //
353  m_Enqueued = FALSE;
354 
356 
357  Unlock(irql);
358 
359  if (m_CallbackLock != NULL) {
361 #if FX_IS_KERNEL_MODE
363 #endif
366  }
367  else {
368 #if FX_IS_KERNEL_MODE
370 #endif
372  }
373 
374  Lock(&irql);
375 
377 
378  //
379  // The workitem can be re-enqueued by the drivers
380  // work item handler routine. We can't set the work
381  // item completed event until we are sure there are
382  // no outstanding work items.
383  //
384 
385  if (m_WorkItemRunningCount == 0L && m_Enqueued == FALSE) {
387  }
388 
389  Unlock(irql);
390 }
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
BOOLEAN m_Enqueued
Definition: fxworkitem.hpp:61
FxCallbackLock * m_CallbackLock
Definition: fxworkitem.hpp:81
PFN_WDF_WORKITEM m_Callback
Definition: fxworkitem.hpp:92
KIRQL irql
Definition: wave.h:1
VOID Set(VOID)
Definition: fxwaitlock.hpp:144
WDFWORKITEM GetHandle(VOID)
Definition: fxworkitem.hpp:193
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
FORCEINLINE VOID FxPerfTraceWorkItem(_In_ PVOID DriverCallback)
virtual void Lock(__out PKIRQL PreviousIrql)=0
FxCREvent m_WorkItemCompleted
Definition: fxworkitem.hpp:98
ULONG m_WorkItemRunningCount
Definition: fxworkitem.hpp:69
static const WCHAR L[]
Definition: oid.c:1250
virtual void Unlock(__in KIRQL PreviousIrql)=0
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
#define NULL
Definition: types.h:112
FX_TRACK_DRIVER(fxDriverGlobals)
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124

Member Data Documentation

◆ m_Callback

PFN_WDF_WORKITEM FxWorkItem::m_Callback
private

Definition at line 92 of file fxworkitem.hpp.

Referenced by FxWorkItem(), Initialize(), WorkItemHandler(), and ~FxWorkItem().

◆ m_CallbackLock

FxCallbackLock* FxWorkItem::m_CallbackLock
private

Definition at line 81 of file fxworkitem.hpp.

Referenced by FxWorkItem(), Initialize(), and WorkItemHandler().

◆ m_CallbackLockObject

FxObject* FxWorkItem::m_CallbackLockObject
private

Definition at line 87 of file fxworkitem.hpp.

Referenced by FxWorkItem(), and Initialize().

◆ m_Enqueued

BOOLEAN FxWorkItem::m_Enqueued
private

Definition at line 61 of file fxworkitem.hpp.

Referenced by Enqueue(), FxWorkItem(), WorkItemHandler(), and ~FxWorkItem().

◆ m_Object

FxObject* FxWorkItem::m_Object
private

◆ m_RunningDown

BOOLEAN FxWorkItem::m_RunningDown
private

Definition at line 56 of file fxworkitem.hpp.

Referenced by Dispose(), Enqueue(), FxWorkItem(), and ~FxWorkItem().

◆ m_WorkItem

MxWorkItem FxWorkItem::m_WorkItem
private

Definition at line 53 of file fxworkitem.hpp.

Referenced by Enqueue(), GetWorkItemPtr(), Initialize(), and ~FxWorkItem().

◆ m_WorkItemCompleted

FxCREvent FxWorkItem::m_WorkItemCompleted
private

Definition at line 98 of file fxworkitem.hpp.

Referenced by Enqueue(), Initialize(), WaitForSignal(), and WorkItemHandler().

◆ m_WorkItemRunningCount

ULONG FxWorkItem::m_WorkItemRunningCount
private

Definition at line 69 of file fxworkitem.hpp.

Referenced by FxWorkItem(), WorkItemHandler(), and ~FxWorkItem().

◆ m_WorkItemThread

MxThread FxWorkItem::m_WorkItemThread
private

Definition at line 105 of file fxworkitem.hpp.

Referenced by FlushAndRundown(), FlushAndWait(), and FxWorkItem().

◆ WorkItemThunk

VOID FxWorkItem::WorkItemThunk
staticprivate

Definition at line 216 of file fxworkitem.hpp.

Referenced by Enqueue().


The documentation for this class was generated from the following files: