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);
29 KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
30 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
35 PKDEVICE_QUEUE_ENTRY entry;
37 DPRINT("KeInsertByKeyDeviceQueue()\n");
39 DeviceQueueEntry->Key=SortKey;
41 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
43 if (!DeviceQueue->Busy)
45 DeviceQueue->Busy=TRUE;
46 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
50 current=DeviceQueue->ListHead.Flink;
51 while (current!=(&DeviceQueue->ListHead))
53 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry);
54 if (entry->Key < SortKey)
56 InsertBeforeEntryInList(&DeviceQueue->ListHead,
57 &DeviceQueueEntry->Entry,
59 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
62 current = current->Flink;
64 InsertTailList(&DeviceQueue->ListHead,&DeviceQueueEntry->Entry);
66 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
72 KeRemoveByKeyDeviceQueue (
73 PKDEVICE_QUEUE DeviceQueue,
79 PKDEVICE_QUEUE_ENTRY entry;
81 assert_irql(DISPATCH_LEVEL);
82 assert(DeviceQueue!=NULL);
83 assert(DeviceQueue->Busy);
85 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
87 current = DeviceQueue->ListHead.Flink;
88 while (current != &DeviceQueue->ListHead)
90 entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry);
91 if (entry->Key < SortKey ||
92 current->Flink == &DeviceQueue->ListHead)
94 RemoveEntryList(current);
95 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
98 current = current->Flink;
100 DeviceQueue->Busy = FALSE;
101 KeReleaseSpinLock(&DeviceQueue->Lock, oldlvl);
107 KeRemoveDeviceQueue (
108 PKDEVICE_QUEUE DeviceQueue
111 * FUNCTION: Removes an entry from a device queue
113 * DeviceQueue = Queue to remove the entry
114 * RETURNS: The removed entry
118 PLIST_ENTRY list_entry;
119 PKDEVICE_QUEUE_ENTRY entry;
121 DPRINT("KeRemoveDeviceQueue(DeviceQueue %x)\n",DeviceQueue);
123 assert_irql(DISPATCH_LEVEL);
124 assert(DeviceQueue!=NULL);
125 assert(DeviceQueue->Busy);
127 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
129 list_entry = RemoveHeadList(&DeviceQueue->ListHead);
130 if (list_entry==(&DeviceQueue->ListHead))
132 DeviceQueue->Busy=FALSE;
133 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
136 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
138 entry = CONTAINING_RECORD(list_entry,KDEVICE_QUEUE_ENTRY,Entry);
142 #endif /* LIBCAPTIVE */
146 KeInitializeDeviceQueue (
147 PKDEVICE_QUEUE DeviceQueue
150 * FUNCTION: Intializes a device queue
152 * DeviceQueue = Device queue to initialize
155 assert(DeviceQueue!=NULL);
156 InitializeListHead(&DeviceQueue->ListHead);
157 DeviceQueue->Busy=FALSE;
158 KeInitializeSpinLock(&DeviceQueue->Lock);
165 KeInsertDeviceQueue (
166 PKDEVICE_QUEUE DeviceQueue,
167 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
170 * FUNCTION: Inserts an entry in a device queue
172 * DeviceQueue = Queue to insert the entry in
173 * DeviceQueueEntry = Entry to insert
174 * RETURNS: False is the device queue wasn't busy
180 KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl);
182 if (!DeviceQueue->Busy)
184 DeviceQueue->Busy=TRUE;
185 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
189 InsertTailList(&DeviceQueue->ListHead,
190 &DeviceQueueEntry->Entry);
191 DeviceQueueEntry->Key=0;
193 KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl);
199 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
200 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
206 #endif /* LIBCAPTIVE */