ReactOS 0.4.15-dev-7958-gcd0bb1a
FxEventQueue Struct Reference

#include <fxeventqueue.hpp>

Inheritance diagram for FxEventQueue:
Collaboration diagram for FxEventQueue:

Public Member Functions

 FxEventQueue (__in UCHAR QueueDepth)
 
_Must_inspect_result_ NTSTATUS Initialize (__in PFX_DRIVER_GLOBALS DriverGlobals)
 
 _Acquires_lock_ (this->m_QueueLock) __drv_maxIRQL(DISPATCH_LEVEL) __drv_setsIRQL(DISPATCH_LEVEL) VOID Lock(__out __drv_deref(__drv_savesIRQL) PKIRQL Irql)
 
 _Releases_lock_ (this->m_QueueLock) __drv_requiresIRQL(DISPATCH_LEVEL) VOID Unlock(__in __drv_restoresIRQL KIRQL Irql)
 
BOOLEAN IsFull (VOID)
 
BOOLEAN IsEmpty (VOID)
 
VOID IncrementHead (VOID)
 
UCHAR GetHead (VOID)
 
UCHAR InsertAtHead (VOID)
 
UCHAR InsertAtTail (VOID)
 
UCHAR IncrementHistoryIndex (VOID)
 
BOOLEAN IsClosedLocked (VOID)
 
VOID GetFinishedState (__inout FxPostProcessInfo *Info)
 
BOOLEAN SetFinished (__in FxCREvent *Event)
 
VOID SetDelayedDeletion (VOID)
 
- Public Member Functions inherited from FxStump
PVOID operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
PVOID operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in POOL_TYPE PoolType)
 
VOID operator delete (__in PVOID pointer)
 
PVOID operator new[] (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
VOID operator delete[] (__in PVOID pointer)
 

Public Attributes

FxWaitLockInternal m_StateMachineLock
 

Protected Member Functions

VOID Configure (__in FxPkgPnp *Pnp, __in PFN_PNP_EVENT_WORKER WorkerRoutine, __in PVOID Context)
 
BOOLEAN QueueToThreadWorker (VOID)
 
VOID EventQueueWorker (VOID)
 
BOOLEAN IsIdleLocked (VOID)
 
- Protected Member Functions inherited from FxStump
 FxStump (VOID)
 

Protected Attributes

UCHAR m_QueueHead
 
UCHAR m_QueueTail
 
UCHAR m_QueueDepth
 
UCHAR m_HistoryIndex
 
FxPkgPnpm_PkgPnp
 
PVOID m_EventWorkerContext
 
MxLock m_QueueLock
 
PFN_PNP_EVENT_WORKER m_EventWorker
 
FxCREventm_WorkItemFinished
 
union {
   UCHAR   m_QueueFlags
 
   struct {
      UCHAR   WorkItemQueued: 1
 
      UCHAR   Closed: 1
 
      UCHAR   DelayDeletion: 1
 
   }   m_QueueFlagsByName
 
}; 
 
UCHAR m_WorkItemRunningCount
 

Detailed Description

Definition at line 51 of file fxeventqueue.hpp.

Constructor & Destructor Documentation

◆ FxEventQueue()

FxEventQueue::FxEventQueue ( __in UCHAR  QueueDepth)

Definition at line 36 of file eventqueue.cpp.

39{
40 m_PkgPnp = NULL;
42
44 m_QueueHead = 0;
45 m_QueueTail = 0;
46 m_QueueDepth = QueueDepth;
47
49 m_QueueFlags = 0x0;
51}
#define NULL
Definition: types.h:112
UCHAR m_HistoryIndex
UCHAR m_WorkItemRunningCount
FxPkgPnp * m_PkgPnp
FxCREvent * m_WorkItemFinished
PFN_PNP_EVENT_WORKER m_EventWorker

Member Function Documentation

◆ _Acquires_lock_()

FxEventQueue::_Acquires_lock_ ( this->  m_QueueLock)
inline

Definition at line 62 of file fxeventqueue.hpp.

70 {
71 m_QueueLock.Acquire(Irql);
72 }
_Out_ PKIRQL Irql
Definition: csq.h:179
MxLock m_QueueLock

◆ _Releases_lock_()

FxEventQueue::_Releases_lock_ ( this->  m_QueueLock)
inline

Definition at line 74 of file fxeventqueue.hpp.

81 {
82 m_QueueLock.Release(Irql);
83 }

◆ Configure()

VOID FxEventQueue::Configure ( __in FxPkgPnp Pnp,
__in PFN_PNP_EVENT_WORKER  WorkerRoutine,
__in PVOID  Context 
)
protected

Definition at line 77 of file eventqueue.cpp.

82{
83 m_PkgPnp = Pnp;
86
87 return;
88}
_Must_inspect_result_ _In_ PFLT_CALLBACK_DATA _In_ PFLT_DEFERRED_IO_WORKITEM_ROUTINE WorkerRoutine
Definition: fltkernel.h:1977
PVOID m_EventWorkerContext

Referenced by FxWorkItemEventQueue::Init(), and FxThreadedEventQueue::Init().

◆ EventQueueWorker()

VOID FxEventQueue::EventQueueWorker ( VOID  )
protected

Definition at line 229 of file eventqueue.cpp.

240{
242 KIRQL irql;
244
245#if (FX_CORE_MODE==FX_CORE_KERNEL_MODE)
247#endif
248
249 //
250 // Cache away m_PkgPnp while we know we still have a valid object. Once
251 // we Unlock() after the worker routine, the object could be gone until
252 // the worker routine set a flag postponing deletion.
253 //
255
256 Lock(&irql);
257
259
260 //
261 // Clear the queued flag, so that it's clear that the work item can
262 // be safely re-enqueued.
263 //
264 m_QueueFlags &= ~FxEventQueueFlagWorkItemQueued;
265
266 //
267 // We should only see this count rise to a small number (like 10 or so).
268 //
271
272 Unlock(irql);
273
274 //
275 // Call the function that will actually run the state machine.
276 //
278
279 Lock(&irql);
282 Unlock(irql);
283
284 //
285 // NOTE: There is no need to use a reference count to keep this event queue
286 // (and the containing state machine) alive. Instead, the thread
287 // which wants to delete the state machine must wait for this work
288 // item to exit. If there was a reference to release, we would have
289 // a race between Unlock()ing and releasing the reference if the state
290 // machine moved into the finished state and deletes the device after
291 // we dropped the lock, but before we released the reference.
292 //
293 // This is important in that the device deletion can trigger
294 // DriverUnload to run before the release executes. DriverUnload
295 // frees the IFR buffer. If this potential release logs something to
296 // the IFR, you would bugcheck. Since it is impossible to defensively
297 // prevent all destructors from logging to the IFR, we can't use a
298 // ref count here to keep the queue alive.
299 //
300
301 //
302 // If Evaluate needs to use pPkgPnp, then the call to the worker routine
303 // above made sure that pPkgPnp has not yet been freed.
304 //
305 info.Evaluate(pPkgPnp);
306}
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591
FX_TRACK_DRIVER(fxDriverGlobals)
FxPkgPnp * pPkgPnp
@ FxEventQueueFlagWorkItemQueued
#define ASSERT(a)
Definition: mode.c:44
@ Unlock
Definition: ntsecapi.h:294
VOID GetFinishedState(__inout FxPostProcessInfo *Info)
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

◆ GetFinishedState()

VOID FxEventQueue::GetFinishedState ( __inout FxPostProcessInfo Info)
inline

Definition at line 165 of file fxeventqueue.hpp.

168 {
169 if (IsIdleLocked()) {
171 m_QueueFlags &= ~FxEventQueueFlagDelayDeletion;
172 Info->m_DeleteObject = TRUE;
173 }
174
175 if (IsClosedLocked()) {
176 Info->m_Event = m_WorkItemFinished;
178 }
179 }
180 }
#define TRUE
Definition: types.h:120
@ FxEventQueueFlagDelayDeletion
BOOLEAN IsIdleLocked(VOID)
BOOLEAN IsClosedLocked(VOID)
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by EventQueueWorker(), FxPkgPnp::PnpProcessEventInner(), FxPkgPnp::PowerPolicyProcessEventInner(), FxPkgPnp::PowerProcessEventInner(), FxDevicePwrRequirementMachine::ProcessEventInner(), and FxWakeInterruptMachine::ProcessEventInner().

◆ GetHead()

◆ IncrementHead()

◆ IncrementHistoryIndex()

◆ Initialize()

_Must_inspect_result_ NTSTATUS FxEventQueue::Initialize ( __in PFX_DRIVER_GLOBALS  DriverGlobals)

Definition at line 55 of file eventqueue.cpp.

58{
60
61 //
62 // For KM, lock initialize always succeeds. For UM, it might fail.
63 //
65 if (!NT_SUCCESS(status)) {
68 "Initializing state machine lock failed for EventQueue 0x%p, "
69 "status %!STATUS!",
70 this, status);
71 }
72
73 return status;
74}
LONG NTSTATUS
Definition: precomp.h:26
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize()
Definition: fxwaitlock.hpp:235
#define TRACINGPNP
Definition: dbgtrace.h:67
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
DriverGlobals
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FxWaitLockInternal m_StateMachineLock
Definition: ps.c:97

Referenced by FxPkgFdo::_Create(), and FxInterrupt::CreateWakeInterruptMachine().

◆ InsertAtHead()

UCHAR FxEventQueue::InsertAtHead ( VOID  )
inline

◆ InsertAtTail()

UCHAR FxEventQueue::InsertAtTail ( VOID  )
inline

Definition at line 127 of file fxeventqueue.hpp.

130 {
131 UCHAR index;
132
133 // Save the index which is the current tail
135
136 // goto next slot
138
139 // return the old tail as the slot to insert at
140 return index;
141 }
#define index(s, c)
Definition: various.h:29
GLuint index
Definition: glext.h:6031

Referenced by FxPkgPnp::PnpProcessEvent(), FxPkgPnp::PowerPolicyProcessEvent(), FxPkgPnp::PowerProcessEvent(), FxDevicePwrRequirementMachine::ProcessEvent(), and FxWakeInterruptMachine::ProcessEvent().

◆ IsClosedLocked()

◆ IsEmpty()

BOOLEAN FxEventQueue::IsEmpty ( VOID  )
inline

◆ IsFull()

◆ IsIdleLocked()

BOOLEAN FxEventQueue::IsIdleLocked ( VOID  )
inlineprotected

Definition at line 211 of file fxeventqueue.hpp.

214 {
215 //
216 // We are idle if there is no work item queued, no work item running,
217 // and there are no events in the queue. Since m_WorkItemQueued is
218 // cleared before we enter the state machine, we must also track the
219 // number of work items running.
220 //
222 m_WorkItemRunningCount == 0x0 &&
223 IsEmpty()) {
224 return TRUE;
225 }
226 else {
227 return FALSE;
228 }
229 }
@ IsEmpty
Definition: atl_ax.c:995

Referenced by GetFinishedState(), and SetFinished().

◆ QueueToThreadWorker()

BOOLEAN FxEventQueue::QueueToThreadWorker ( VOID  )
protected

Definition at line 154 of file eventqueue.cpp.

179{
180 KIRQL irql;
182
183 Lock(&irql);
184
185 //
186 // For one reason or another, we couldn't run the state machine on this
187 // thread. So queue a work item to do it.
188 //
189 if (IsEmpty()) {
190 //
191 // There is no work to do. This means that the caller inserted the
192 // event into the queue, dropped the lock, and then another thread came
193 // in and processed the event.
194 //
195 // This check also helps in the rundown case when the queue is closing
196 // and the following happens between 2 thread:
197 // #1 #2
198 // insert event
199 // drop lock
200 // process event queue
201 // queue goes to empty, so event is set
202 // try to queue work item
203 //
204 result = FALSE;
205
208 "WDFDEVICE 0x%p !devobj 0x%p not queueing work item to process "
209 "event queue", m_PkgPnp->GetDevice()->GetHandle(),
211 }
212 else if ((m_QueueFlags & FxEventQueueFlagWorkItemQueued) == 0x00) {
214 result = TRUE;
215 }
216 else {
217 //
218 // Somebody is already in the process of enqueuing the work item.
219 //
220 result = FALSE;
221 }
222
223 Unlock(irql);
224
225 return result;
226}
unsigned char BOOLEAN
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
__inline CfxDevice * GetDevice(VOID)
Definition: fxpackage.hpp:46
GLuint64EXT * result
Definition: glext.h:11304
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29

Referenced by FxWorkItemEventQueue::QueueToThread(), and FxThreadedEventQueue::QueueToThread().

◆ SetDelayedDeletion()

VOID FxEventQueue::SetDelayedDeletion ( VOID  )

Definition at line 135 of file eventqueue.cpp.

138{
139 KIRQL irql;
140
143 "WDFDEVICE 0x%p !devobj 0x%p delaying deletion to outside state machine",
146
147 Lock(&irql);
150 Unlock(irql);
151}

◆ SetFinished()

BOOLEAN FxEventQueue::SetFinished ( __in FxCREvent Event)

Definition at line 91 of file eventqueue.cpp.

109{
110 KIRQL irql;
112
113 result = TRUE;
114
115 Lock(&irql);
118
120
121 if (result == FALSE) {
123 }
124
125 Unlock(irql);
126
127 if (result) {
128 Event->Set();
129 }
130
131 return result;
132}

Referenced by FxPkgPnp::CleanupStateMachines().

Member Data Documentation

◆ 

union { ... } FxEventQueue::@4759

◆ Closed

UCHAR FxEventQueue::Closed

Definition at line 279 of file fxeventqueue.hpp.

◆ DelayDeletion

UCHAR FxEventQueue::DelayDeletion

Definition at line 280 of file fxeventqueue.hpp.

◆ m_EventWorker

PFN_PNP_EVENT_WORKER FxEventQueue::m_EventWorker
protected

Definition at line 260 of file fxeventqueue.hpp.

Referenced by Configure(), EventQueueWorker(), and FxEventQueue().

◆ m_EventWorkerContext

PVOID FxEventQueue::m_EventWorkerContext
protected

Definition at line 249 of file fxeventqueue.hpp.

Referenced by Configure(), and EventQueueWorker().

◆ m_HistoryIndex

UCHAR FxEventQueue::m_HistoryIndex
protected

Definition at line 241 of file fxeventqueue.hpp.

Referenced by FxEventQueue(), and IncrementHistoryIndex().

◆ m_PkgPnp

◆ m_QueueDepth

UCHAR FxEventQueue::m_QueueDepth
protected

◆ m_QueueFlags

◆ 

struct { ... } FxEventQueue::m_QueueFlagsByName

◆ m_QueueHead

UCHAR FxEventQueue::m_QueueHead
protected

Definition at line 233 of file fxeventqueue.hpp.

Referenced by FxEventQueue(), GetHead(), IncrementHead(), InsertAtHead(), IsEmpty(), and IsFull().

◆ m_QueueLock

MxLock FxEventQueue::m_QueueLock
protected

Definition at line 254 of file fxeventqueue.hpp.

Referenced by _Acquires_lock_(), and _Releases_lock_().

◆ m_QueueTail

UCHAR FxEventQueue::m_QueueTail
protected

Definition at line 236 of file fxeventqueue.hpp.

Referenced by FxEventQueue(), InsertAtTail(), IsEmpty(), and IsFull().

◆ m_StateMachineLock

◆ m_WorkItemFinished

FxCREvent* FxEventQueue::m_WorkItemFinished
protected

Definition at line 267 of file fxeventqueue.hpp.

Referenced by FxEventQueue(), GetFinishedState(), and SetFinished().

◆ m_WorkItemRunningCount

UCHAR FxEventQueue::m_WorkItemRunningCount
protected

Definition at line 289 of file fxeventqueue.hpp.

Referenced by EventQueueWorker(), FxEventQueue(), and IsIdleLocked().

◆ WorkItemQueued

UCHAR FxEventQueue::WorkItemQueued

Definition at line 278 of file fxeventqueue.hpp.


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