2 * COPYRIGHT: See COPYING in the top level directory
3 * PURPOSE: ReactOS kernel
4 * FILE: ntoskrnl/ke/kqueue.c
5 * PURPOSE: Implement device queues
6 * PROGRAMMER: David Welch (welch@mcmail.com)
11 /* INCLUDES ****************************************************************/
13 #include <ddk/ntddk.h>
16 #include <internal/debug.h>
18 /* FUNCTIONS *****************************************************************/
21 InsertBeforeEntryInList(PLIST_ENTRY Head, PLIST_ENTRY After, PLIST_ENTRY Entry)
23 InsertHeadList(After, Entry);
27 KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
28 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
33 PKDEVICE_QUEUE_ENTRY entry;
35 DPRINT("KeInsertByKeyDeviceQueue()\n");
37 DeviceQueueEntry->Key=SortKey;
39 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
41 if (!DeviceQueue->Busy)
43 DeviceQueue->Busy=TRUE;
44 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
48 current=DeviceQueue->ListHead.Flink;
49 while (current!=(&DeviceQueue->ListHead))
51 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry);
52 if (entry->Key < SortKey)
54 InsertBeforeEntryInList(&DeviceQueue->ListHead,
55 &DeviceQueueEntry->Entry,
57 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
60 current = current->Flink;
62 InsertTailList(&DeviceQueue->ListHead,&DeviceQueueEntry->Entry);
64 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
70 KeRemoveByKeyDeviceQueue (
71 PKDEVICE_QUEUE DeviceQueue,
77 PKDEVICE_QUEUE_ENTRY entry;
79 assert_irql(DISPATCH_LEVEL);
80 assert(DeviceQueue!=NULL);
81 assert(DeviceQueue->Busy);
83 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
85 current = DeviceQueue->ListHead.Flink;
86 while (current != &DeviceQueue->ListHead)
88 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry);
89 if (entry->Key < SortKey ||
90 current->Flink == &DeviceQueue->ListHead)
92 RemoveEntryList(current);
93 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
96 current = current->Flink;
98 DeviceQueue->Busy = FALSE;
99 KeReleaseSpinLock(&DeviceQueue->Lock, oldlvl);
105 KeRemoveDeviceQueue (
106 PKDEVICE_QUEUE DeviceQueue
109 * FUNCTION: Removes an entry from a device queue
111 * DeviceQueue = Queue to remove the entry
112 * RETURNS: The removed entry
116 PLIST_ENTRY list_entry;
117 PKDEVICE_QUEUE_ENTRY entry;
119 DPRINT("KeRemoveDeviceQueue(DeviceQueue %x)\n",DeviceQueue);
121 assert_irql(DISPATCH_LEVEL);
122 assert(DeviceQueue!=NULL);
123 assert(DeviceQueue->Busy);
125 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
127 list_entry = RemoveHeadList(&DeviceQueue->ListHead);
128 if (list_entry==(&DeviceQueue->ListHead))
130 DeviceQueue->Busy=FALSE;
131 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
134 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
136 entry = CONTAINING_RECORD(list_entry,KDEVICE_QUEUE_ENTRY,Entry);
142 KeInitializeDeviceQueue (
143 PKDEVICE_QUEUE DeviceQueue
146 * FUNCTION: Intializes a device queue
148 * DeviceQueue = Device queue to initialize
151 assert(DeviceQueue!=NULL);
152 InitializeListHead(&DeviceQueue->ListHead);
153 DeviceQueue->Busy=FALSE;
154 KeInitializeSpinLock(&DeviceQueue->Lock);
159 KeInsertDeviceQueue (
160 PKDEVICE_QUEUE DeviceQueue,
161 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
164 * FUNCTION: Inserts an entry in a device queue
166 * DeviceQueue = Queue to insert the entry in
167 * DeviceQueueEntry = Entry to insert
168 * RETURNS: False is the device queue wasn't busy
174 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
176 if (!DeviceQueue->Busy)
178 DeviceQueue->Busy=TRUE;
179 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
183 InsertTailList(&DeviceQueue->ListHead,
184 &DeviceQueueEntry->Entry);
185 DeviceQueueEntry->Key=0;
187 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
193 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
194 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)