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 *****************************************************************/
23 InsertBeforeEntryInList(PLIST_ENTRY Head, PLIST_ENTRY After, PLIST_ENTRY Entry)
25 InsertHeadList(After, Entry);
32 KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
33 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
38 PKDEVICE_QUEUE_ENTRY entry;
40 DPRINT("KeInsertByKeyDeviceQueue()\n");
42 DeviceQueueEntry->SortKey=SortKey;
44 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
46 if (!DeviceQueue->Busy)
48 DeviceQueue->Busy=TRUE;
49 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
53 current=DeviceQueue->DeviceListHead.Flink;
54 while (current!=(&DeviceQueue->DeviceListHead))
56 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,DeviceListEntry);
57 if (entry->SortKey < SortKey)
59 InsertBeforeEntryInList(&DeviceQueue->DeviceListHead,
60 &DeviceQueueEntry->DeviceListEntry,
62 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
65 current = current->Flink;
67 InsertTailList(&DeviceQueue->DeviceListHead,&DeviceQueueEntry->DeviceListEntry);
69 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
78 KeRemoveByKeyDeviceQueue (
79 PKDEVICE_QUEUE DeviceQueue,
85 PKDEVICE_QUEUE_ENTRY entry;
87 assert_irql(DISPATCH_LEVEL);
88 assert(DeviceQueue!=NULL);
89 assert(DeviceQueue->Busy);
91 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
93 current = DeviceQueue->DeviceListHead.Flink;
94 while (current != &DeviceQueue->DeviceListHead)
96 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,DeviceListEntry);
97 if (entry->SortKey < SortKey ||
98 current->Flink == &DeviceQueue->DeviceListHead)
100 RemoveEntryList(current);
101 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
104 current = current->Flink;
106 DeviceQueue->Busy = FALSE;
107 KeReleaseSpinLock(&DeviceQueue->Lock, oldlvl);
116 KeRemoveDeviceQueue (
117 PKDEVICE_QUEUE DeviceQueue
120 * FUNCTION: Removes an entry from a device queue
122 * DeviceQueue = Queue to remove the entry
123 * RETURNS: The removed entry
127 PLIST_ENTRY list_entry;
128 PKDEVICE_QUEUE_ENTRY entry;
130 DPRINT("KeRemoveDeviceQueue(DeviceQueue %x)\n",DeviceQueue);
132 assert_irql(DISPATCH_LEVEL);
133 assert(DeviceQueue!=NULL);
134 assert(DeviceQueue->Busy);
136 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
138 list_entry = RemoveHeadList(&DeviceQueue->DeviceListHead);
139 if (list_entry==(&DeviceQueue->DeviceListHead))
141 DeviceQueue->Busy=FALSE;
142 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
145 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
147 entry = CONTAINING_RECORD(list_entry,KDEVICE_QUEUE_ENTRY,DeviceListEntry);
151 #endif /* LIBCAPTIVE */
158 KeInitializeDeviceQueue (
159 PKDEVICE_QUEUE DeviceQueue
162 * FUNCTION: Intializes a device queue
164 * DeviceQueue = Device queue to initialize
167 assert(DeviceQueue!=NULL);
168 InitializeListHead(&DeviceQueue->DeviceListHead);
169 DeviceQueue->Busy=FALSE;
170 KeInitializeSpinLock(&DeviceQueue->Lock);
180 KeInsertDeviceQueue (
181 PKDEVICE_QUEUE DeviceQueue,
182 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
185 * FUNCTION: Inserts an entry in a device queue
187 * DeviceQueue = Queue to insert the entry in
188 * DeviceQueueEntry = Entry to insert
189 * RETURNS: False is the device queue wasn't busy
195 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
197 if (!DeviceQueue->Busy)
199 DeviceQueue->Busy=TRUE;
200 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
204 InsertTailList(&DeviceQueue->DeviceListHead,
205 &DeviceQueueEntry->DeviceListEntry);
206 DeviceQueueEntry->SortKey=0;
208 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
217 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
218 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
224 #endif /* LIBCAPTIVE */