mirror of
https://github.com/reactos/reactos.git
synced 2024-10-15 05:37:44 +00:00
- Update the last remaining old function, KeSetBasePriority. Use new locks and assertions, and also make use of KiComputeNewPriority.
svn path=/trunk/; revision=24035
This commit is contained in:
parent
1ee6196a10
commit
4300e4effe
|
@ -1036,29 +1036,34 @@ KeSetSystemAffinityThread(IN KAFFINITY Affinity)
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
LONG
|
LONG
|
||||||
STDCALL
|
NTAPI
|
||||||
KeSetBasePriorityThread(PKTHREAD Thread,
|
KeSetBasePriorityThread(IN PKTHREAD Thread,
|
||||||
LONG Increment)
|
IN LONG Increment)
|
||||||
{
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
|
KPRIORITY OldBasePriority, Priority, BasePriority;
|
||||||
|
LONG OldIncrement;
|
||||||
PKPROCESS Process;
|
PKPROCESS Process;
|
||||||
KPRIORITY Priority;
|
BOOLEAN Released;
|
||||||
KPRIORITY CurrentBasePriority;
|
ASSERT_THREAD(Thread);
|
||||||
KPRIORITY BasePriority;
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
||||||
BOOLEAN Released = FALSE;
|
|
||||||
LONG CurrentIncrement;
|
/* Get the process */
|
||||||
|
Process = Thread->ApcState.Process;
|
||||||
|
|
||||||
/* Lock the Dispatcher Database */
|
/* Lock the Dispatcher Database */
|
||||||
OldIrql = KeAcquireDispatcherDatabaseLock();
|
OldIrql = KiAcquireDispatcherLock();
|
||||||
|
|
||||||
/* Get the process and calculate current BP and BPI */
|
/* Lock the thread */
|
||||||
Process = Thread->ApcStatePointer[0]->Process;
|
KiAcquireThreadLock(Thread);
|
||||||
CurrentBasePriority = Thread->BasePriority;
|
|
||||||
CurrentIncrement = CurrentBasePriority - Process->BasePriority;
|
|
||||||
|
|
||||||
/* Change to use the SI if Saturation was used */
|
/* Save the old base priority and increment */
|
||||||
if (Thread->Saturation) CurrentIncrement = (HIGH_PRIORITY + 1) / 2 *
|
OldBasePriority = Thread->BasePriority;
|
||||||
Thread->Saturation;
|
OldIncrement = OldBasePriority - Process->BasePriority;
|
||||||
|
|
||||||
|
/* If priority saturation happened, use the saturated increment */
|
||||||
|
if (Thread->Saturation) OldIncrement = (HIGH_PRIORITY + 1) / 2 *
|
||||||
|
Thread->Saturation;
|
||||||
|
|
||||||
/* Now check if saturation is being used for the new value */
|
/* Now check if saturation is being used for the new value */
|
||||||
if (abs(Increment) >= ((HIGH_PRIORITY + 1) / 2))
|
if (abs(Increment) >= ((HIGH_PRIORITY + 1) / 2))
|
||||||
|
@ -1073,66 +1078,80 @@ KeSetBasePriorityThread(PKTHREAD Thread,
|
||||||
{
|
{
|
||||||
/* Check if it's too low */
|
/* Check if it's too low */
|
||||||
if (BasePriority < LOW_REALTIME_PRIORITY)
|
if (BasePriority < LOW_REALTIME_PRIORITY)
|
||||||
|
{
|
||||||
|
/* Set it to the lowest real time level */
|
||||||
BasePriority = LOW_REALTIME_PRIORITY;
|
BasePriority = LOW_REALTIME_PRIORITY;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if it's too high */
|
/* Check if it's too high */
|
||||||
if (BasePriority > HIGH_PRIORITY) BasePriority = HIGH_PRIORITY;
|
if (BasePriority > HIGH_PRIORITY) BasePriority = HIGH_PRIORITY;
|
||||||
|
|
||||||
/* We are at RTP, so use the raw BP */
|
/* We are at real time, so use the raw base priority */
|
||||||
Priority = BasePriority;
|
Priority = BasePriority;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Check if it's entering RTP */
|
/* Check if it's entering the real time range */
|
||||||
if (BasePriority >= LOW_REALTIME_PRIORITY)
|
if (BasePriority >= LOW_REALTIME_PRIORITY)
|
||||||
|
{
|
||||||
|
/* Set it to the highest dynamic level */
|
||||||
BasePriority = LOW_REALTIME_PRIORITY - 1;
|
BasePriority = LOW_REALTIME_PRIORITY - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if it's too low */
|
/* Check if it's too low and normalize it */
|
||||||
if (BasePriority <= LOW_PRIORITY)
|
if (BasePriority <= LOW_PRIORITY) BasePriority = 1;
|
||||||
BasePriority = 1;
|
|
||||||
|
|
||||||
/* If Saturation is used, then use the raw BP */
|
/* Check if Saturation is used */
|
||||||
if (Thread->Saturation)
|
if (Thread->Saturation)
|
||||||
{
|
{
|
||||||
|
/* Use the raw base priority */
|
||||||
Priority = BasePriority;
|
Priority = BasePriority;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Calculate the new priority */
|
/* Otherwise, calculate the new priority */
|
||||||
Priority = Thread->Priority + (BasePriority - CurrentBasePriority)-
|
Priority = KiComputeNewPriority(Thread);
|
||||||
Thread->PriorityDecrement;
|
|
||||||
|
|
||||||
/* Make sure it won't enter RTP ranges */
|
/* Check if it entered the real-time range */
|
||||||
if (Priority >= LOW_REALTIME_PRIORITY)
|
if (Priority >= LOW_REALTIME_PRIORITY)
|
||||||
|
{
|
||||||
|
/* Normalize it down to the highest dynamic priority */
|
||||||
Priority = LOW_REALTIME_PRIORITY - 1;
|
Priority = LOW_REALTIME_PRIORITY - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally set the new base priority */
|
/* Finally set the new base priority */
|
||||||
Thread->BasePriority = BasePriority;
|
Thread->BasePriority = (SCHAR)BasePriority;
|
||||||
|
|
||||||
/* Reset the decrements */
|
/* Reset the decrements */
|
||||||
Thread->PriorityDecrement = 0;
|
Thread->PriorityDecrement = 0;
|
||||||
|
|
||||||
/* If the priority will change, reset quantum and change it for real */
|
/* Check if we're changing priority after all */
|
||||||
if (Priority != Thread->Priority)
|
if (Priority != Thread->Priority)
|
||||||
{
|
{
|
||||||
|
/* Reset the quantum and do the actual priority modification */
|
||||||
Thread->Quantum = Thread->QuantumReset;
|
Thread->Quantum = Thread->QuantumReset;
|
||||||
KiSetPriorityThread(Thread, Priority, &Released);
|
KiSetPriorityThread(Thread, Priority, &Released);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release Lock if needed */
|
/* Release thread lock */
|
||||||
|
KiReleaseThreadLock(Thread);
|
||||||
|
|
||||||
|
/* Check if lock was released */
|
||||||
if (!Released)
|
if (!Released)
|
||||||
{
|
{
|
||||||
KeReleaseDispatcherDatabaseLock(OldIrql);
|
/* Release the dispatcher database */
|
||||||
|
KiReleaseDispatcherLock(OldIrql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Lower IRQL only */
|
||||||
KeLowerIrql(OldIrql);
|
KeLowerIrql(OldIrql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the Old Increment */
|
/* Return old increment */
|
||||||
return CurrentIncrement;
|
return OldIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue