Don't remove the WaitEntry twice (in KiInsertQueue).
[reactos.git] / reactos / ntoskrnl / ke / queue.c
index 53d451a..5dd7bce 100644 (file)
@@ -270,8 +270,8 @@ KeRemoveQueue(IN PKQUEUE Queue,
                 WaitBlock->WaitType = WaitAny;
 
                 /* Link the timer to this Wait Block */
-                InitializeListHead(&Timer->Header.WaitListHead);
-                InsertTailList(&Timer->Header.WaitListHead, &WaitBlock->WaitListEntry);
+                Timer->Header.WaitListHead.Flink = &WaitBlock->WaitListEntry;
+                Timer->Header.WaitListHead.Blink = &WaitBlock->WaitListEntry;
 
                 /* Create Timer */
                 DPRINT("Creating Timer with timeout %I64d\n", *Timeout);
@@ -286,12 +286,16 @@ KeRemoveQueue(IN PKQUEUE Queue,
             InsertTailList(&Queue->Header.WaitListHead,
                            &WaitBlock->WaitListEntry);
 
-            /* Block the Thread */
-            DPRINT("Blocking the Thread: %x %x!\n", KeGetCurrentThread(), Thread);
-            KiBlockThread(&Status,
-                          FALSE,
-                          WaitMode,
-                          WrQueue);
+            /* Setup the wait information */
+            Thread->WaitMode = WaitMode;
+            Thread->WaitReason = WrQueue;
+            Thread->Alertable = FALSE;
+            Thread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
+            Thread->State = Waiting;
+
+            /* Find a new thread to run */
+            DPRINT("Swapping threads\n");
+            Status = KiSwapThread();
 
             /* Reset the wait reason */
             Thread->WaitReason = 0;
@@ -466,9 +470,6 @@ KiInsertQueue(IN PKQUEUE Queue,
         Queue->CurrentCount++;
         Thread->WaitStatus = (NTSTATUS)Entry;
 
-        /* Remove the thread from its wait list */
-        RemoveEntryList(&Thread->WaitListEntry);
-
         /* Check if there's a Thread Timer */
         if (Thread->Timer.Header.Inserted)
         {