- Fix utterly messed up unblocking/readying thread logic.

- KiUnblockThread becomes KiReadyThread and doesn't perform priority modifications anymore. Also removed a large block of code that was #if 0ed out.
- KiAbortWaitThread now does priority modifications (and better then before), then calls KiReadyThread.
- Inserting a queue now *READIES A THREAD ONLY* instead of removing all its waits!

svn path=/trunk/; revision=23055
This commit is contained in:
Alex Ionescu
2006-07-13 22:52:18 +00:00
parent eab221b08b
commit 8d372c2271
7 changed files with 75 additions and 93 deletions
+5 -10
View File
@@ -133,14 +133,9 @@ KiSwapThread(
VOID
);
/* Removes a thread out of a block state. */
VOID
STDCALL
KiUnblockThread(
PKTHREAD Thread,
PNTSTATUS WaitStatus,
KPRIORITY Increment
);
NTAPI
KiReadyThread(IN PKTHREAD Thread);
NTSTATUS
STDCALL
@@ -331,9 +326,9 @@ KiTestAlert(VOID);
VOID
FASTCALL
KiAbortWaitThread(
PKTHREAD Thread,
NTSTATUS WaitStatus,
KPRIORITY Increment
IN PKTHREAD Thread,
IN NTSTATUS WaitStatus,
IN KPRIORITY Increment
);
VOID
+2 -2
View File
@@ -132,8 +132,8 @@ KeSignalGateBoostPriority(IN PKGATE Gate)
/* Increment the Queue's active threads */
if (WaitThread->Queue) WaitThread->Queue->CurrentCount++;
/* Reschedule the Thread */
KiUnblockThread(WaitThread, &WaitStatus, EVENT_INCREMENT);
/* FIXME: This isn't really correct!!! */
KiAbortWaitThread(WaitThread, WaitStatus, EVENT_INCREMENT);
}
quit:
+5 -77
View File
@@ -202,84 +202,12 @@ KiDispatchThread(ULONG NewThreadStatus)
}
VOID
STDCALL
KiUnblockThread(PKTHREAD Thread,
PNTSTATUS WaitStatus,
KPRIORITY Increment)
NTAPI
KiReadyThread(IN PKTHREAD Thread)
{
if (Terminated == Thread->State) {
DPRINT1("Can't unblock thread 0x%x because it's terminating\n",
Thread);
} else if (Ready == Thread->State ||
Running == Thread->State) {
DPRINT1("Can't unblock thread 0x%x because it's %s\n",
Thread, (Thread->State == Ready ? "ready" : "running"));
} else {
LONG Processor;
KAFFINITY Affinity;
/* FIXME: This propably isn't the right way to do it... */
/* No it's not... i'll fix it later-- Alex */
if (Thread->Priority < LOW_REALTIME_PRIORITY &&
Thread->BasePriority < LOW_REALTIME_PRIORITY - 2) {
if (!Thread->PriorityDecrement && !Thread->DisableBoost) {
Thread->Priority = Thread->BasePriority + Increment;
Thread->PriorityDecrement = Increment;
}
/* Also decrease quantum */
Thread->Quantum--;
} else {
Thread->Quantum = Thread->QuantumReset;
}
if (WaitStatus != NULL) {
Thread->WaitStatus = *WaitStatus;
}
Thread->State = Ready;
KiInsertIntoThreadList(Thread->Priority, Thread);
Processor = KeGetCurrentProcessorNumber();
Affinity = Thread->Affinity;
if (!(IdleProcessorMask & (1 << Processor) & Affinity) &&
(IdleProcessorMask & ~(1 << Processor) & Affinity)) {
LONG i;
for (i = 0; i < KeNumberProcessors - 1; i++) {
Processor++;
if (Processor >= KeNumberProcessors) {
Processor = 0;
}
if (IdleProcessorMask & (1 << Processor) & Affinity) {
#if 0
/* FIXME:
* Reschedule the threads on an other processor
*/
KeReleaseDispatcherDatabaseLockFromDpcLevel();
KiRequestReschedule(Processor);
KeAcquireDispatcherDatabaseLockAtDpcLevel();
#endif
break;
}
}
}
}
/* Makes a thread ready */
Thread->State = Ready;
KiInsertIntoThreadList(Thread->Priority, Thread);
}
VOID
+1 -1
View File
@@ -117,7 +117,7 @@ KiInsertQueue(IN PKQUEUE Queue,
}
/* Reschedule the Thread */
KiUnblockThread(Thread, NULL, 0);
KiReadyThread(Thread);
}
else
{
+60 -1
View File
@@ -127,6 +127,7 @@ KiAbortWaitThread(IN PKTHREAD Thread,
{
PKWAIT_BLOCK WaitBlock;
PKTIMER Timer;
LONG NewPriority;
/* Update wait status */
Thread->WaitStatus |= WaitStatus;
@@ -158,8 +159,66 @@ KiAbortWaitThread(IN PKTHREAD Thread,
/* Increment the Queue's active threads */
if (Thread->Queue) Thread->Queue->CurrentCount++;
/* Check if this is a non-RT thread */
if (Thread->Priority < LOW_REALTIME_PRIORITY)
{
/* Check if boosting is enabled and we can boost */
if (!(Thread->DisableBoost) && !(Thread->PriorityDecrement))
{
/* We can boost, so calculate the new priority */
NewPriority = Thread->BasePriority + Increment;
if (NewPriority > Thread->Priority)
{
/* Make sure the new priority wouldn't push the thread to RT */
if (NewPriority >= LOW_REALTIME_PRIORITY)
{
/* Set it just before the RT zone */
Thread->Priority = LOW_REALTIME_PRIORITY - 1;
}
else
{
/* Otherwise, set our calculated priority */
Thread->Priority = NewPriority;
}
}
}
/* Check if this is a high-priority thread */
if (Thread->BasePriority >= 14)
{
/* It is, simply reset the quantum */
Thread->Quantum = Thread->QuantumReset;
}
else
{
/* Otherwise, decrease quantum */
Thread->Quantum--;
if (Thread->Quantum <= 0)
{
/* We've went below 0, reset it */
Thread->Quantum = Thread->QuantumReset;
/* Apply per-quantum priority decrement */
Thread->Priority -= (Thread->PriorityDecrement + 1);
if (Thread->Priority < Thread->BasePriority)
{
/* We've went too low, reset it */
Thread->Priority = Thread->BasePriority;
}
/* Delete per-quantum decrement */
Thread->PriorityDecrement = 0;
}
}
}
else
{
/* For real time threads, just reset the quantum */
Thread->Quantum = Thread->QuantumReset;
}
/* Reschedule the Thread */
KiUnblockThread(Thread, NULL, Increment);
KiReadyThread(Thread);
}
VOID
+1 -1
View File
@@ -110,7 +110,7 @@ PsInitIdleThread(VOID)
FALSE);
oldIrql = KeAcquireDispatcherDatabaseLock ();
KiUnblockThread(&IdleThread->Tcb, NULL, 0);
KiReadyThread(&IdleThread->Tcb);
KeReleaseDispatcherDatabaseLock(oldIrql);
KeGetCurrentPrcb()->IdleThread = &IdleThread->Tcb;
+1 -1
View File
@@ -353,7 +353,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
/* Dispatch thread */
OldIrql = KeAcquireDispatcherDatabaseLock ();
KiUnblockThread(&Thread->Tcb, NULL, 0);
KiReadyThread(&Thread->Tcb);
KeReleaseDispatcherDatabaseLock(OldIrql);
/* Return */