Author: ion Date: Fri Jul 14 02:52:18 2006 New Revision: 23055
URL: http://svn.reactos.org/svn/reactos?rev=23055&view=rev Log: - 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!
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h trunk/reactos/ntoskrnl/ke/gate.c trunk/reactos/ntoskrnl/ke/kthread.c trunk/reactos/ntoskrnl/ke/queue.c trunk/reactos/ntoskrnl/ke/wait.c trunk/reactos/ntoskrnl/ps/idle.c trunk/reactos/ntoskrnl/ps/thread.c
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ke.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ke.h Fri Jul 14 02:52:18 2006 @@ -133,14 +133,9 @@ VOID );
-/* Removes a thread out of a block state. */ -VOID -STDCALL -KiUnblockThread( - PKTHREAD Thread, - PNTSTATUS WaitStatus, - KPRIORITY Increment -); +VOID +NTAPI +KiReadyThread(IN PKTHREAD Thread);
NTSTATUS STDCALL @@ -331,9 +326,9 @@ VOID FASTCALL KiAbortWaitThread( - PKTHREAD Thread, - NTSTATUS WaitStatus, - KPRIORITY Increment + IN PKTHREAD Thread, + IN NTSTATUS WaitStatus, + IN KPRIORITY Increment );
VOID
Modified: trunk/reactos/ntoskrnl/ke/gate.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/gate.c?rev=2305... ============================================================================== --- trunk/reactos/ntoskrnl/ke/gate.c (original) +++ trunk/reactos/ntoskrnl/ke/gate.c Fri Jul 14 02:52:18 2006 @@ -132,8 +132,8 @@ /* 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:
Modified: trunk/reactos/ntoskrnl/ke/kthread.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/kthread.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/ke/kthread.c (original) +++ trunk/reactos/ntoskrnl/ke/kthread.c Fri Jul 14 02:52:18 2006 @@ -202,84 +202,12 @@ }
VOID -STDCALL -KiUnblockThread(PKTHREAD Thread, - PNTSTATUS WaitStatus, - KPRIORITY Increment) -{ - 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; - } - } - } - } +NTAPI +KiReadyThread(IN PKTHREAD Thread) +{ + /* Makes a thread ready */ + Thread->State = Ready; + KiInsertIntoThreadList(Thread->Priority, Thread); }
VOID
Modified: trunk/reactos/ntoskrnl/ke/queue.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/queue.c?rev=230... ============================================================================== --- trunk/reactos/ntoskrnl/ke/queue.c (original) +++ trunk/reactos/ntoskrnl/ke/queue.c Fri Jul 14 02:52:18 2006 @@ -117,7 +117,7 @@ }
/* Reschedule the Thread */ - KiUnblockThread(Thread, NULL, 0); + KiReadyThread(Thread); } else {
Modified: trunk/reactos/ntoskrnl/ke/wait.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/wait.c?rev=2305... ============================================================================== --- trunk/reactos/ntoskrnl/ke/wait.c (original) +++ trunk/reactos/ntoskrnl/ke/wait.c Fri Jul 14 02:52:18 2006 @@ -127,6 +127,7 @@ { PKWAIT_BLOCK WaitBlock; PKTIMER Timer; + LONG NewPriority;
/* Update wait status */ Thread->WaitStatus |= WaitStatus; @@ -158,8 +159,66 @@ /* 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
Modified: trunk/reactos/ntoskrnl/ps/idle.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/idle.c?rev=2305... ============================================================================== --- trunk/reactos/ntoskrnl/ps/idle.c (original) +++ trunk/reactos/ntoskrnl/ps/idle.c Fri Jul 14 02:52:18 2006 @@ -110,7 +110,7 @@ FALSE);
oldIrql = KeAcquireDispatcherDatabaseLock (); - KiUnblockThread(&IdleThread->Tcb, NULL, 0); + KiReadyThread(&IdleThread->Tcb); KeReleaseDispatcherDatabaseLock(oldIrql);
KeGetCurrentPrcb()->IdleThread = &IdleThread->Tcb;
Modified: trunk/reactos/ntoskrnl/ps/thread.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/thread.c?rev=23... ============================================================================== --- trunk/reactos/ntoskrnl/ps/thread.c (original) +++ trunk/reactos/ntoskrnl/ps/thread.c Fri Jul 14 02:52:18 2006 @@ -353,7 +353,7 @@
/* Dispatch thread */ OldIrql = KeAcquireDispatcherDatabaseLock (); - KiUnblockThread(&Thread->Tcb, NULL, 0); + KiReadyThread(&Thread->Tcb); KeReleaseDispatcherDatabaseLock(OldIrql);
/* Return */