- Implement KiRecalculateDueTime to handle cases where a timeout wait has been interu...
[reactos.git] / reactos / ntoskrnl / include / internal / ke_x.h
index 66ccf72..4199406 100644 (file)
@@ -87,7 +87,7 @@
             }                                                               \\r
                                                                             \\r
             /* Insert it into the Mutant List */                            \\r
-            InsertHeadList(&Thread->MutantListHead,                         \\r
+            InsertHeadList(Thread->MutantListHead.Blink,                    \\r
                            &(Object)->MutantListEntry);                     \\r
         }                                                                   \\r
     }                                                                       \\r
         }                                                                   \\r
                                                                             \\r
         /* Insert it into the Mutant List */                                \\r
-        InsertHeadList(&Thread->MutantListHead,                             \\r
+        InsertHeadList(Thread->MutantListHead.Blink,                        \\r
                        &(Object)->MutantListEntry);                         \\r
     }                                                                       \\r
 }\r
     }                                                                       \\r
 }\r
 \r
+//\r
+// Recalculates the due time\r
+//\r
+PLARGE_INTEGER\r
+FORCEINLINE\r
+KiRecalculateDueTime(IN PLARGE_INTEGER OriginalDueTime,\r
+                     IN PLARGE_INTEGER DueTime,\r
+                     IN OUT PLARGE_INTEGER NewDueTime)\r
+{\r
+    /* Don't do anything for absolute waits */\r
+    if (OriginalDueTime->QuadPart >= 0) return OriginalDueTime;\r
+\r
+    /* Otherwise, query the interrupt time and recalculate */\r
+    NewDueTime->QuadPart = KeQueryInterruptTime();\r
+    NewDueTime->QuadPart -= DueTime->QuadPart;\r
+    return NewDueTime;\r
+}\r
+\r
+//\r
+// Determines wether a thread should be added to the wait list\r
+//\r
+#define KiCheckThreadStackSwap(WaitMode, Thread, Swappable)                 \\r
+{                                                                           \\r
+    /* Check the required conditions */                                     \\r
+    if ((WaitMode != KernelMode) &&                                         \\r
+        (Thread->EnableStackSwap) &&                                        \\r
+        (Thread->Priority >= (LOW_REALTIME_PRIORITY + 9)))                  \\r
+    {                                                                       \\r
+        /* We are go for swap */                                            \\r
+        Swappable = TRUE;                                                   \\r
+    }                                                                       \\r
+    else                                                                    \\r
+    {                                                                       \\r
+        /* Don't swap the thread */                                         \\r
+        Swappable = FALSE;                                                  \\r
+    }                                                                       \\r
+}\r
+\r
+//\r
+// Adds a thread to the wait list\r
+//\r
+#define KiAddThreadToWaitList(Thread, Swappable)                            \\r
+{                                                                           \\r
+    /* Make sure it's swappable */                                          \\r
+    if (Swappable)                                                          \\r
+    {                                                                       \\r
+        /* Insert it into the PRCB's List */                                \\r
+        InsertTailList(&KeGetCurrentPrcb()->WaitListHead,                   \\r
+                       &Thread->WaitListEntry);                             \\r
+    }                                                                       \\r
+}\r
+\r
 //\r
 // Rules for checking alertability:\r
 //  - For Alertable waits ONLY:\r