- Fix (and optimize) KeRemoveByKeyDeviceQueue() routine.

- Add DPRINTs for easier testing/debugging.

svn path=/trunk/; revision=26165
This commit is contained in:
Aleksey Bragin 2007-03-25 13:23:30 +00:00
parent 34713168d4
commit 51147f6c84

View file

@ -45,6 +45,8 @@ KeInsertDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
BOOLEAN Inserted;
ASSERT_DEVICE_QUEUE(DeviceQueue);
DPRINT("KeInsertDeviceQueue() DevQueue %p, Entry %p\n", DeviceQueue, DeviceQueueEntry);
/* Lock the queue */
KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
@ -86,6 +88,8 @@ KeInsertByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
BOOLEAN Inserted;
ASSERT_DEVICE_QUEUE(DeviceQueue);
DPRINT("KeInsertByKeyDeviceQueue() DevQueue %p, Entry %p, SortKey 0x%x\n", DeviceQueue, DeviceQueueEntry, SortKey);
/* Lock the queue */
KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
@ -129,6 +133,8 @@ KeRemoveDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
KLOCK_QUEUE_HANDLE DeviceLock;
ASSERT_DEVICE_QUEUE(DeviceQueue);
DPRINT("KeRemoveDeviceQueue() DevQueue %p\n", DeviceQueue);
/* Lock the queue */
KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
ASSERT(DeviceQueue->Busy);
@ -172,6 +178,8 @@ KeRemoveByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
KLOCK_QUEUE_HANDLE DeviceLock;
ASSERT_DEVICE_QUEUE(DeviceQueue);
DPRINT("KeRemoveByKeyDeviceQueue() DevQueue %p, SortKey 0x%x\n", DeviceQueue, SortKey);
/* Lock the queue */
KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
ASSERT(DeviceQueue->Busy);
@ -184,6 +192,23 @@ KeRemoveByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
ReturnEntry = NULL;
}
else
{
/* If SortKey is greater than the last key, then return the first entry right away */
ListEntry = &DeviceQueue->DeviceListHead;
ReturnEntry = CONTAINING_RECORD(ListEntry->Blink,
KDEVICE_QUEUE_ENTRY,
DeviceListEntry);
if (SortKey >= ReturnEntry->SortKey)
{
ReturnEntry = CONTAINING_RECORD(ListEntry->Flink,
KDEVICE_QUEUE_ENTRY,
DeviceListEntry);
/* Remove it from the list */
RemoveEntryList(&ReturnEntry->DeviceListEntry);
}
else
{
/* Find entry with SortKey greater than or equal to the passed-in SortKey */
LIST_FOR_EACH(ReturnEntry, &DeviceQueue->DeviceListHead, KDEVICE_QUEUE_ENTRY, DeviceListEntry)
@ -206,6 +231,7 @@ KeRemoveByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
KDEVICE_QUEUE_ENTRY,
DeviceListEntry);
}
}
/* Set it as non-inserted */
ReturnEntry->Inserted = FALSE;
@ -231,6 +257,8 @@ KeRemoveByKeyDeviceQueueIfBusy(IN PKDEVICE_QUEUE DeviceQueue,
KLOCK_QUEUE_HANDLE DeviceLock;
ASSERT_DEVICE_QUEUE(DeviceQueue);
DPRINT("KeRemoveByKeyDeviceQueueIfBusy() DevQueue %p, SortKey 0x%x\n", DeviceQueue, SortKey);
/* Lock the queue */
KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
@ -288,6 +316,8 @@ KeRemoveEntryDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
KLOCK_QUEUE_HANDLE DeviceLock;
ASSERT_DEVICE_QUEUE(DeviceQueue);
DPRINT("KeRemoveEntryDeviceQueue() DevQueue %p, Entry %p\n", DeviceQueue, DeviceQueueEntry);
/* Lock the queue */
KiAcquireDeviceQueueLock(DeviceQueue, &DeviceLock);
ASSERT(DeviceQueue->Busy);