ReactOS  0.4.13-dev-73-gcfe54aa
devqueue.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for devqueue.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KeInitializeDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue)
 
BOOLEAN NTAPI KeInsertDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue, IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
 
BOOLEAN NTAPI KeInsertByKeyDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue, IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry, IN ULONG SortKey)
 
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue)
 
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveByKeyDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue, IN ULONG SortKey)
 
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveByKeyDeviceQueueIfBusy (IN PKDEVICE_QUEUE DeviceQueue, IN ULONG SortKey)
 
BOOLEAN NTAPI KeRemoveEntryDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue, IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file devqueue.c.

Function Documentation

◆ KeInitializeDeviceQueue()

VOID NTAPI KeInitializeDeviceQueue ( IN PKDEVICE_QUEUE  DeviceQueue)

Definition at line 22 of file devqueue.c.

23 {
24  /* Initialize the Header */
25  DeviceQueue->Type = DeviceQueueObject;
26  DeviceQueue->Size = sizeof(KDEVICE_QUEUE);
27 
28  /* Initialize the Listhead and Spinlock */
29  InitializeListHead(&DeviceQueue->DeviceListHead);
30  KeInitializeSpinLock(&DeviceQueue->Lock);
31 
32  /* Set it as busy */
33  DeviceQueue->Busy=FALSE;
34 }
struct _KDEVICE_QUEUE KDEVICE_QUEUE
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by HalpDmaAllocateChildAdapter(), IoCreateController(), IoCreateDevice(), SpiAllocateLunExtension(), Test_Initialize(), and Tests_Insert_And_Delete().

◆ KeInsertByKeyDeviceQueue()

BOOLEAN NTAPI KeInsertByKeyDeviceQueue ( IN PKDEVICE_QUEUE  DeviceQueue,
IN PKDEVICE_QUEUE_ENTRY  DeviceQueueEntry,
IN ULONG  SortKey 
)

Definition at line 83 of file devqueue.c.

86 {
87  KLOCK_QUEUE_HANDLE DeviceLock;
88  BOOLEAN Inserted;
89  PLIST_ENTRY NextEntry;
90  PKDEVICE_QUEUE_ENTRY LastEntry;
91  ASSERT_DEVICE_QUEUE(DeviceQueue);
92 
93  DPRINT("KeInsertByKeyDeviceQueue() DevQueue %p, Entry %p, SortKey 0x%x\n", DeviceQueue, DeviceQueueEntry, SortKey);
94 
95  /* Lock the queue */
96  KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
97 
98  /* Set the Sort Key */
100 
101  /* Check if it's not busy */
102  if (!DeviceQueue->Busy)
103  {
104  /* Set it as busy */
105  Inserted = FALSE;
106  DeviceQueue->Busy = TRUE;
107  }
108  else
109  {
110  /* Make sure the list isn't empty */
111  NextEntry = &DeviceQueue->DeviceListHead;
112  if (!IsListEmpty(NextEntry))
113  {
114  /* Get the last entry */
115  LastEntry = CONTAINING_RECORD(NextEntry->Blink,
117  DeviceListEntry);
118 
119  /* Check if our sort key is lower */
120  if (SortKey < LastEntry->SortKey)
121  {
122  /* Loop each sort key */
123  do
124  {
125  /* Get the next entry */
126  NextEntry = NextEntry->Flink;
127  LastEntry = CONTAINING_RECORD(NextEntry,
129  DeviceListEntry);
130 
131  /* Keep looping until we find a place to insert */
132  } while (SortKey >= LastEntry->SortKey);
133  }
134  }
135 
136  /* Now insert us */
138  Inserted = TRUE;
139  }
140 
141  /* Release the lock */
142  KiReleaseDeviceQueueLock(&DeviceLock);
143 
144  /* Return the state */
145  return Inserted;
146 }
#define TRUE
Definition: types.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
_Inout_ PKDEVICE_QUEUE_ENTRY _In_ ULONG SortKey
Definition: kefuncs.h:352
FORCEINLINE VOID KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:668
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
LIST_ENTRY DeviceListEntry
Definition: ketypes.h:567
Definition: ketypes.h:566
FORCEINLINE VOID KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:688
ULONG SortKey
Definition: ketypes.h:568
#define ASSERT_DEVICE_QUEUE(Object)
_Inout_ PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
Definition: kefuncs.h:352

Referenced by IoStartPacket(), ScsiPortDispatchScsi(), and SpiProcessCompletedRequest().

◆ KeInsertDeviceQueue()

BOOLEAN NTAPI KeInsertDeviceQueue ( IN PKDEVICE_QUEUE  DeviceQueue,
IN PKDEVICE_QUEUE_ENTRY  DeviceQueueEntry 
)

Definition at line 41 of file devqueue.c.

43 {
44  KLOCK_QUEUE_HANDLE DeviceLock;
45  BOOLEAN Inserted;
46  ASSERT_DEVICE_QUEUE(DeviceQueue);
47 
48  DPRINT("KeInsertDeviceQueue() DevQueue %p, Entry %p\n", DeviceQueue, DeviceQueueEntry);
49 
50  /* Lock the queue */
51  KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
52 
53  /* Check if it's not busy */
54  if (!DeviceQueue->Busy)
55  {
56  /* Set it as busy */
57  Inserted = FALSE;
58  DeviceQueue->Busy = TRUE;
59  }
60  else
61  {
62  /* Insert it into the list */
63  Inserted = TRUE;
64  InsertTailList(&DeviceQueue->DeviceListHead,
66  }
67 
68  /* Sert the Insert state into the entry */
69  DeviceQueueEntry->Inserted = Inserted;
70 
71  /* Release the lock */
72  KiReleaseDeviceQueueLock(&DeviceLock);
73 
74  /* Return the state */
75  return Inserted;
76 }
#define TRUE
Definition: types.h:120
FORCEINLINE VOID KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:668
#define InsertTailList(ListHead, Entry)
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN Inserted
Definition: ketypes.h:569
LIST_ENTRY DeviceListEntry
Definition: ketypes.h:567
FORCEINLINE VOID KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:688
#define ASSERT_DEVICE_QUEUE(Object)
_Inout_ PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
Definition: kefuncs.h:352

Referenced by HalAllocateAdapterChannel(), IoAllocateController(), IoStartPacket(), and Tests_Insert_And_Delete().

◆ KeRemoveByKeyDeviceQueue()

PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveByKeyDeviceQueue ( IN PKDEVICE_QUEUE  DeviceQueue,
IN ULONG  SortKey 
)

Definition at line 197 of file devqueue.c.

199 {
200  PLIST_ENTRY NextEntry;
201  PKDEVICE_QUEUE_ENTRY ReturnEntry;
202  KLOCK_QUEUE_HANDLE DeviceLock;
203  ASSERT_DEVICE_QUEUE(DeviceQueue);
204 
205  DPRINT("KeRemoveByKeyDeviceQueue() DevQueue %p, SortKey 0x%x\n", DeviceQueue, SortKey);
206 
207  /* Lock the queue */
208  KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
209  ASSERT(DeviceQueue->Busy);
210 
211  /* Check if this is an empty queue */
212  if (IsListEmpty(&DeviceQueue->DeviceListHead))
213  {
214  /* Set it to idle and return nothing*/
215  DeviceQueue->Busy = FALSE;
216  ReturnEntry = NULL;
217  }
218  else
219  {
220  /* If SortKey is greater than the last key, then return the first entry right away */
221  NextEntry = &DeviceQueue->DeviceListHead;
222  ReturnEntry = CONTAINING_RECORD(NextEntry->Blink,
224  DeviceListEntry);
225 
226  /* Check if we can just get the first entry */
227  if (ReturnEntry->SortKey <= SortKey)
228  {
229  /* Get the first entry */
230  ReturnEntry = CONTAINING_RECORD(NextEntry->Flink,
232  DeviceListEntry);
233  }
234  else
235  {
236  /* Loop the list */
237  NextEntry = DeviceQueue->DeviceListHead.Flink;
238  while (TRUE)
239  {
240  /* Make sure we don't go beyond the end of the queue */
241  ASSERT(NextEntry != &DeviceQueue->DeviceListHead);
242 
243  /* Get the next entry and check if the key is low enough */
244  ReturnEntry = CONTAINING_RECORD(NextEntry,
246  DeviceListEntry);
247  if (SortKey <= ReturnEntry->SortKey) break;
248 
249  /* Try the next one */
250  NextEntry = NextEntry->Flink;
251  }
252  }
253 
254  /* We have an entry, remove it now */
255  RemoveEntryList(&ReturnEntry->DeviceListEntry);
256 
257  /* Set it as non-inserted */
258  ReturnEntry->Inserted = FALSE;
259  }
260 
261  /* Release the lock */
262  KiReleaseDeviceQueueLock(&DeviceLock);
263 
264  /* Return the entry */
265  return ReturnEntry;
266 }
#define TRUE
Definition: types.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
_Inout_ PKDEVICE_QUEUE_ENTRY _In_ ULONG SortKey
Definition: kefuncs.h:352
FORCEINLINE VOID KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:668
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN Inserted
Definition: ketypes.h:569
Definition: typedefs.h:117
LIST_ENTRY DeviceListEntry
Definition: ketypes.h:567
Definition: ketypes.h:566
FORCEINLINE VOID KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:688
ULONG SortKey
Definition: ketypes.h:568
#define ASSERT_DEVICE_QUEUE(Object)

Referenced by IopStartNextPacketByKey(), and SpiGetNextRequestFromLun().

◆ KeRemoveByKeyDeviceQueueIfBusy()

PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveByKeyDeviceQueueIfBusy ( IN PKDEVICE_QUEUE  DeviceQueue,
IN ULONG  SortKey 
)

Definition at line 273 of file devqueue.c.

275 {
276  PLIST_ENTRY NextEntry;
277  PKDEVICE_QUEUE_ENTRY ReturnEntry;
278  KLOCK_QUEUE_HANDLE DeviceLock;
279  ASSERT_DEVICE_QUEUE(DeviceQueue);
280 
281  DPRINT("KeRemoveByKeyDeviceQueueIfBusy() DevQueue %p, SortKey 0x%x\n", DeviceQueue, SortKey);
282 
283  /* Lock the queue */
284  KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
285 
286  /* Check if this is an empty or idle queue */
287  if (!(DeviceQueue->Busy) || (IsListEmpty(&DeviceQueue->DeviceListHead)))
288  {
289  /* Set it to idle and return nothing*/
290  DeviceQueue->Busy = FALSE;
291  ReturnEntry = NULL;
292  }
293  else
294  {
295  /* If SortKey is greater than the last key, then return the first entry right away */
296  NextEntry = &DeviceQueue->DeviceListHead;
297  ReturnEntry = CONTAINING_RECORD(NextEntry->Blink,
299  DeviceListEntry);
300 
301  /* Check if we can just get the first entry */
302  if (ReturnEntry->SortKey <= SortKey)
303  {
304  /* Get the first entry */
305  ReturnEntry = CONTAINING_RECORD(NextEntry->Flink,
307  DeviceListEntry);
308  }
309  else
310  {
311  /* Loop the list */
312  NextEntry = DeviceQueue->DeviceListHead.Flink;
313  while (TRUE)
314  {
315  /* Make sure we don't go beyond the end of the queue */
316  ASSERT(NextEntry != &DeviceQueue->DeviceListHead);
317 
318  /* Get the next entry and check if the key is low enough */
319  ReturnEntry = CONTAINING_RECORD(NextEntry,
321  DeviceListEntry);
322  if (SortKey <= ReturnEntry->SortKey) break;
323 
324  /* Try the next one */
325  NextEntry = NextEntry->Flink;
326  }
327  }
328 
329  /* We have an entry, remove it now */
330  RemoveEntryList(&ReturnEntry->DeviceListEntry);
331 
332  /* Set it as non-inserted */
333  ReturnEntry->Inserted = FALSE;
334  }
335 
336  /* Release the lock */
337  KiReleaseDeviceQueueLock(&DeviceLock);
338 
339  /* Return the entry */
340  return ReturnEntry;
341 }
#define TRUE
Definition: types.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
_Inout_ PKDEVICE_QUEUE_ENTRY _In_ ULONG SortKey
Definition: kefuncs.h:352
FORCEINLINE VOID KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:668
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN Inserted
Definition: ketypes.h:569
Definition: typedefs.h:117
LIST_ENTRY DeviceListEntry
Definition: ketypes.h:567
Definition: ketypes.h:566
FORCEINLINE VOID KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:688
ULONG SortKey
Definition: ketypes.h:568
#define ASSERT_DEVICE_QUEUE(Object)

◆ KeRemoveDeviceQueue()

PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveDeviceQueue ( IN PKDEVICE_QUEUE  DeviceQueue)

Definition at line 153 of file devqueue.c.

154 {
155  PLIST_ENTRY ListEntry;
156  PKDEVICE_QUEUE_ENTRY ReturnEntry;
157  KLOCK_QUEUE_HANDLE DeviceLock;
158  ASSERT_DEVICE_QUEUE(DeviceQueue);
159 
160  DPRINT("KeRemoveDeviceQueue() DevQueue %p\n", DeviceQueue);
161 
162  /* Lock the queue */
163  KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
164  ASSERT(DeviceQueue->Busy);
165 
166  /* Check if this is an empty queue */
167  if (IsListEmpty(&DeviceQueue->DeviceListHead))
168  {
169  /* Set it to idle and return nothing*/
170  DeviceQueue->Busy = FALSE;
171  ReturnEntry = NULL;
172  }
173  else
174  {
175  /* Remove the Entry from the List */
176  ListEntry = RemoveHeadList(&DeviceQueue->DeviceListHead);
177  ReturnEntry = CONTAINING_RECORD(ListEntry,
179  DeviceListEntry);
180 
181  /* Set it as non-inserted */
182  ReturnEntry->Inserted = FALSE;
183  }
184 
185  /* Release the lock */
186  KiReleaseDeviceQueueLock(&DeviceLock);
187 
188  /* Return the entry */
189  return ReturnEntry;
190 }
FORCEINLINE VOID KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:668
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN Inserted
Definition: ketypes.h:569
Definition: typedefs.h:117
Definition: ketypes.h:566
FORCEINLINE VOID KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:688
#define ASSERT_DEVICE_QUEUE(Object)

Referenced by BeepCleanup(), IoFreeAdapterChannel(), IoFreeController(), IopStartNextPacket(), ScsiPortDispatchScsi(), and Tests_Insert_And_Delete().

◆ KeRemoveEntryDeviceQueue()

BOOLEAN NTAPI KeRemoveEntryDeviceQueue ( IN PKDEVICE_QUEUE  DeviceQueue,
IN PKDEVICE_QUEUE_ENTRY  DeviceQueueEntry 
)

Definition at line 348 of file devqueue.c.

350 {
351  BOOLEAN OldState;
352  KLOCK_QUEUE_HANDLE DeviceLock;
353  ASSERT_DEVICE_QUEUE(DeviceQueue);
354 
355  DPRINT("KeRemoveEntryDeviceQueue() DevQueue %p, Entry %p\n", DeviceQueue, DeviceQueueEntry);
356 
357  /* Lock the queue */
358  KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
359  ASSERT(DeviceQueue->Busy);
360 
361  /* Check the insertion state */
362  OldState = DeviceQueueEntry->Inserted;
363  if (OldState)
364  {
365  /* Remove it */
368  }
369 
370  /* Unlock and return old state */
371  KiReleaseDeviceQueueLock(&DeviceLock);
372  return OldState;
373 }
FORCEINLINE VOID KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:668
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN Inserted
Definition: ketypes.h:569
LIST_ENTRY DeviceListEntry
Definition: ketypes.h:567
FORCEINLINE VOID KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock)
Definition: ke_x.h:688
#define ASSERT_DEVICE_QUEUE(Object)
_Inout_ PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
Definition: kefuncs.h:352

Referenced by BeepCancel(), and Tests_Insert_And_Delete().