- Simplify KiWaitTest.

- Add _ADJUST_REASON
- Reformat some ke_x.h wait macros to use simpler/shorter variable names.

svn path=/trunk/; revision=25480
This commit is contained in:
Alex Ionescu 2007-01-16 02:24:19 +00:00
parent ce501f07c6
commit 73d8fac4c0
3 changed files with 39 additions and 75 deletions

View file

@ -280,6 +280,16 @@ typedef enum _KTHREAD_STATE
#endif
} KTHREAD_STATE, *PKTHREAD_STATE;
//
// Adjust reasons
//
typedef enum _ADJUST_REASON
{
AdjustNone = 0,
AdjustUnwait = 1,
AdjustBoost = 2
} ADJUST_REASON;
//
// Process States
//

View file

@ -503,28 +503,27 @@ KxUnwaitThread(IN DISPATCHER_HEADER *Object,
IN KPRIORITY Increment)
{
PLIST_ENTRY WaitEntry, WaitList;
PKWAIT_BLOCK CurrentWaitBlock;
PKWAIT_BLOCK WaitBlock;
PKTHREAD WaitThread;
ULONG WaitKey;
/* Loop the Wait Entries */
WaitList = &Object->WaitListHead;
ASSERT(IsListEmpty(&Object->WaitListHead) == FALSE);
WaitEntry = WaitList->Flink;
do
{
/* Get the current wait block */
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry,
KWAIT_BLOCK,
WaitListEntry);
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
/* Get the waiting thread */
WaitThread = CurrentWaitBlock->Thread;
WaitThread = WaitBlock->Thread;
/* Check the current Wait Mode */
if (CurrentWaitBlock->WaitType == WaitAny)
if (WaitBlock->WaitType == WaitAny)
{
/* Use the actual wait key */
WaitKey = CurrentWaitBlock->WaitKey;
WaitKey = WaitBlock->WaitKey;
}
else
{
@ -549,37 +548,34 @@ KxUnwaitThreadForEvent(IN PKEVENT Event,
IN KPRIORITY Increment)
{
PLIST_ENTRY WaitEntry, WaitList;
PKWAIT_BLOCK CurrentWaitBlock;
PKWAIT_BLOCK WaitBlock;
PKTHREAD WaitThread;
/* Loop the Wait Entries */
WaitList = &Event->Header.WaitListHead;
ASSERT(IsListEmpty(&Event->Header.WaitListHead) == FALSE);
WaitEntry = WaitList->Flink;
do
{
/* Get the current wait block */
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry,
KWAIT_BLOCK,
WaitListEntry);
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
/* Get the waiting thread */
WaitThread = CurrentWaitBlock->Thread;
WaitThread = WaitBlock->Thread;
/* Check the current Wait Mode */
if (CurrentWaitBlock->WaitType == WaitAny)
if (WaitBlock->WaitType == WaitAny)
{
/* Un-signal it */
Event->Header.SignalState = 0;
/* Un-signal the event and unwait the thread */
KiUnwaitThread(WaitThread, CurrentWaitBlock->WaitKey, Increment);
KiUnwaitThread(WaitThread, WaitBlock->WaitKey, Increment);
break;
}
else
{
/* Unwait the thread with STATUS_KERNEL_APC */
KiUnwaitThread(WaitThread, STATUS_KERNEL_APC, Increment);
}
/* Unwait the thread with STATUS_KERNEL_APC */
KiUnwaitThread(WaitThread, STATUS_KERNEL_APC, Increment);
/* Next entry */
WaitEntry = WaitList->Flink;

View file

@ -42,75 +42,33 @@ FASTCALL
KiWaitTest(IN PVOID ObjectPointer,
IN KPRIORITY Increment)
{
PLIST_ENTRY WaitEntry;
PLIST_ENTRY WaitList;
PKWAIT_BLOCK CurrentWaitBlock;
PKWAIT_BLOCK NextWaitBlock;
PLIST_ENTRY WaitEntry, WaitList;
PKWAIT_BLOCK WaitBlock;
PKTHREAD WaitThread;
PKMUTANT FirstObject = ObjectPointer, Object;
PKMUTANT FirstObject = ObjectPointer;
NTSTATUS WaitStatus;
/* Loop the Wait Entries */
WaitList = &FirstObject->Header.WaitListHead;
WaitEntry = WaitList->Flink;
while ((FirstObject->Header.SignalState > 0) &&
(WaitEntry != WaitList))
while ((FirstObject->Header.SignalState > 0) && (WaitEntry != WaitList))
{
/* Get the current wait block */
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry,
KWAIT_BLOCK,
WaitListEntry);
WaitThread = CurrentWaitBlock->Thread;
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
WaitThread = WaitBlock->Thread;
WaitStatus = STATUS_KERNEL_APC;
/* Check the current Wait Mode */
if (CurrentWaitBlock->WaitType == WaitAny)
if (WaitBlock->WaitType == WaitAny)
{
/* Easy case, satisfy only this wait */
WaitEntry = WaitEntry->Blink;
WaitStatus = (NTSTATUS)WaitBlock->WaitKey;
KiSatisfyObjectWait(FirstObject, WaitThread);
}
else
{
/* Everything must be satisfied */
NextWaitBlock = CurrentWaitBlock->NextWaitBlock;
/* Loop first to make sure they are valid */
while (NextWaitBlock != CurrentWaitBlock)
{
/* Make sure this isn't a timeout block */
if (NextWaitBlock->WaitKey != STATUS_TIMEOUT)
{
/* Get the object */
Object = NextWaitBlock->Object;
/* Check if this is a mutant */
if ((Object->Header.Type == MutantObject) &&
(Object->Header.SignalState <= 0) &&
(WaitThread == Object->OwnerThread))
{
/* It's a signaled mutant */
}
else if (Object->Header.SignalState <= 0)
{
/* Skip the unwaiting */
goto SkipUnwait;
}
}
/* Go to the next Wait block */
NextWaitBlock = NextWaitBlock->NextWaitBlock;
}
/* All the objects are signaled, we can satisfy */
WaitEntry = WaitEntry->Blink;
KiWaitSatisfyAll(CurrentWaitBlock);
}
/* All waits satisfied, unwait the thread */
KiUnwaitThread(WaitThread, CurrentWaitBlock->WaitKey, Increment);
SkipUnwait:
/* Next entry */
WaitEntry = WaitEntry->Flink;
/* Now do the rest of the unwait */
KiUnwaitThread(WaitThread, WaitStatus, Increment);
WaitEntry = WaitList->Flink;
}
}
@ -166,7 +124,7 @@ KiUnwaitThread(IN PKTHREAD Thread,
/* Tell the scheduler do to the increment when it readies the thread */
ASSERT(Increment >= 0);
Thread->AdjustIncrement = (SCHAR)Increment;
Thread->AdjustReason = 1;
Thread->AdjustReason = AdjustUnwait;
/* Reschedule the Thread */
KiReadyThread(Thread);