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);
30 KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
31 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
36 PKDEVICE_QUEUE_ENTRY entry;
38 DPRINT("KeInsertByKeyDeviceQueue()\n");
40 DeviceQueueEntry->SortKey=SortKey;
42 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
44 if (!DeviceQueue->Busy)
46 DeviceQueue->Busy=TRUE;
47 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
51 current=DeviceQueue->DeviceListHead.Flink;
52 while (current!=(&DeviceQueue->DeviceListHead))
54 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,DeviceListEntry);
55 if (entry->SortKey < SortKey)
57 InsertBeforeEntryInList(&DeviceQueue->DeviceListHead,
58 &DeviceQueueEntry->DeviceListEntry,
60 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
63 current = current->Flink;
65 InsertTailList(&DeviceQueue->DeviceListHead,&DeviceQueueEntry->DeviceListEntry);
67 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
76 KeRemoveByKeyDeviceQueue (
77 PKDEVICE_QUEUE DeviceQueue,
83 PKDEVICE_QUEUE_ENTRY entry;
85 assert_irql(DISPATCH_LEVEL);
86 assert(DeviceQueue!=NULL);
87 assert(DeviceQueue->Busy);
89 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
91 current = DeviceQueue->DeviceListHead.Flink;
92 while (current != &DeviceQueue->DeviceListHead)
94 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,DeviceListEntry);
95 if (entry->SortKey < SortKey ||
96 current->Flink == &DeviceQueue->DeviceListHead)
98 RemoveEntryList(current);
99 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
102 current = current->Flink;
104 DeviceQueue->Busy = FALSE;
105 KeReleaseSpinLock(&DeviceQueue->Lock, oldlvl);
114 KeRemoveDeviceQueue (
115 PKDEVICE_QUEUE DeviceQueue
118 * FUNCTION: Removes an entry from a device queue
120 * DeviceQueue = Queue to remove the entry
121 * RETURNS: The removed entry
125 PLIST_ENTRY list_entry;
126 PKDEVICE_QUEUE_ENTRY entry;
128 DPRINT("KeRemoveDeviceQueue(DeviceQueue %x)\n",DeviceQueue);
130 assert_irql(DISPATCH_LEVEL);
131 assert(DeviceQueue!=NULL);
132 assert(DeviceQueue->Busy);
134 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
136 list_entry = RemoveHeadList(&DeviceQueue->DeviceListHead);
137 if (list_entry==(&DeviceQueue->DeviceListHead))
139 DeviceQueue->Busy=FALSE;
140 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
143 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
145 entry = CONTAINING_RECORD(list_entry,KDEVICE_QUEUE_ENTRY,DeviceListEntry);
154 KeInitializeDeviceQueue (
155 PKDEVICE_QUEUE DeviceQueue
158 * FUNCTION: Intializes a device queue
160 * DeviceQueue = Device queue to initialize
163 assert(DeviceQueue!=NULL);
164 InitializeListHead(&DeviceQueue->DeviceListHead);
165 DeviceQueue->Busy=FALSE;
166 KeInitializeSpinLock(&DeviceQueue->Lock);
174 KeInsertDeviceQueue (
175 PKDEVICE_QUEUE DeviceQueue,
176 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
179 * FUNCTION: Inserts an entry in a device queue
181 * DeviceQueue = Queue to insert the entry in
182 * DeviceQueueEntry = Entry to insert
183 * RETURNS: False is the device queue wasn't busy
189 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
191 if (!DeviceQueue->Busy)
193 DeviceQueue->Busy=TRUE;
194 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
198 InsertTailList(&DeviceQueue->DeviceListHead,
199 &DeviceQueueEntry->DeviceListEntry);
200 DeviceQueueEntry->SortKey=0;
202 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
211 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
212 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)