Author: ion Date: Tue Jan 16 05:24:19 2007 New Revision: 25480
URL: http://svn.reactos.org/svn/reactos?rev=25480&view=rev Log: - Simplify KiWaitTest. - Add _ADJUST_REASON - Reformat some ke_x.h wait macros to use simpler/shorter variable names.
Modified: trunk/reactos/include/ndk/ketypes.h trunk/reactos/ntoskrnl/include/internal/ke_x.h trunk/reactos/ntoskrnl/ke/wait.c
Modified: trunk/reactos/include/ndk/ketypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/ketypes.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/ketypes.h (original) +++ trunk/reactos/include/ndk/ketypes.h Tue Jan 16 05:24:19 2007 @@ -281,6 +281,16 @@ } KTHREAD_STATE, *PKTHREAD_STATE;
// +// Adjust reasons +// +typedef enum _ADJUST_REASON +{ + AdjustNone = 0, + AdjustUnwait = 1, + AdjustBoost = 2 +} ADJUST_REASON; + +// // Process States // typedef enum _KPROCESS_STATE
Modified: trunk/reactos/ntoskrnl/include/internal/ke_x.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ke_x.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ke_x.h Tue Jan 16 05:24:19 2007 @@ -503,28 +503,27 @@ 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 @@ 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;
Modified: trunk/reactos/ntoskrnl/ke/wait.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/wait.c?rev=2548... ============================================================================== --- trunk/reactos/ntoskrnl/ke/wait.c (original) +++ trunk/reactos/ntoskrnl/ke/wait.c Tue Jan 16 05:24:19 2007 @@ -42,75 +42,33 @@ 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 @@ /* 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);