From 73d8fac4c0c7a6eab4ff3ee33a1363ae8f318ef3 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Tue, 16 Jan 2007 02:24:19 +0000 Subject: [PATCH] - Simplify KiWaitTest. - Add _ADJUST_REASON - Reformat some ke_x.h wait macros to use simpler/shorter variable names. svn path=/trunk/; revision=25480 --- reactos/include/ndk/ketypes.h | 10 ++++ reactos/ntoskrnl/include/internal/ke_x.h | 34 +++++------- reactos/ntoskrnl/ke/wait.c | 70 +++++------------------- 3 files changed, 39 insertions(+), 75 deletions(-) diff --git a/reactos/include/ndk/ketypes.h b/reactos/include/ndk/ketypes.h index 6cb747dafa7..4c54152665b 100644 --- a/reactos/include/ndk/ketypes.h +++ b/reactos/include/ndk/ketypes.h @@ -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 // diff --git a/reactos/ntoskrnl/include/internal/ke_x.h b/reactos/ntoskrnl/include/internal/ke_x.h index a21d7ce9a79..ab8542c0472 100644 --- a/reactos/ntoskrnl/include/internal/ke_x.h +++ b/reactos/ntoskrnl/include/internal/ke_x.h @@ -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; diff --git a/reactos/ntoskrnl/ke/wait.c b/reactos/ntoskrnl/ke/wait.c index 2f35b05797e..c1d863cdfb5 100644 --- a/reactos/ntoskrnl/ke/wait.c +++ b/reactos/ntoskrnl/ke/wait.c @@ -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);