mirror of
https://github.com/reactos/reactos.git
synced 2024-07-07 21:25:05 +00:00
- 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:
parent
ce501f07c6
commit
73d8fac4c0
|
@ -280,6 +280,16 @@ typedef enum _KTHREAD_STATE
|
||||||
#endif
|
#endif
|
||||||
} KTHREAD_STATE, *PKTHREAD_STATE;
|
} KTHREAD_STATE, *PKTHREAD_STATE;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Adjust reasons
|
||||||
|
//
|
||||||
|
typedef enum _ADJUST_REASON
|
||||||
|
{
|
||||||
|
AdjustNone = 0,
|
||||||
|
AdjustUnwait = 1,
|
||||||
|
AdjustBoost = 2
|
||||||
|
} ADJUST_REASON;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Process States
|
// Process States
|
||||||
//
|
//
|
||||||
|
|
|
@ -503,28 +503,27 @@ KxUnwaitThread(IN DISPATCHER_HEADER *Object,
|
||||||
IN KPRIORITY Increment)
|
IN KPRIORITY Increment)
|
||||||
{
|
{
|
||||||
PLIST_ENTRY WaitEntry, WaitList;
|
PLIST_ENTRY WaitEntry, WaitList;
|
||||||
PKWAIT_BLOCK CurrentWaitBlock;
|
PKWAIT_BLOCK WaitBlock;
|
||||||
PKTHREAD WaitThread;
|
PKTHREAD WaitThread;
|
||||||
ULONG WaitKey;
|
ULONG WaitKey;
|
||||||
|
|
||||||
/* Loop the Wait Entries */
|
/* Loop the Wait Entries */
|
||||||
WaitList = &Object->WaitListHead;
|
WaitList = &Object->WaitListHead;
|
||||||
|
ASSERT(IsListEmpty(&Object->WaitListHead) == FALSE);
|
||||||
WaitEntry = WaitList->Flink;
|
WaitEntry = WaitList->Flink;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Get the current wait block */
|
/* Get the current wait block */
|
||||||
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry,
|
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
|
||||||
KWAIT_BLOCK,
|
|
||||||
WaitListEntry);
|
|
||||||
|
|
||||||
/* Get the waiting thread */
|
/* Get the waiting thread */
|
||||||
WaitThread = CurrentWaitBlock->Thread;
|
WaitThread = WaitBlock->Thread;
|
||||||
|
|
||||||
/* Check the current Wait Mode */
|
/* Check the current Wait Mode */
|
||||||
if (CurrentWaitBlock->WaitType == WaitAny)
|
if (WaitBlock->WaitType == WaitAny)
|
||||||
{
|
{
|
||||||
/* Use the actual wait key */
|
/* Use the actual wait key */
|
||||||
WaitKey = CurrentWaitBlock->WaitKey;
|
WaitKey = WaitBlock->WaitKey;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -549,37 +548,34 @@ KxUnwaitThreadForEvent(IN PKEVENT Event,
|
||||||
IN KPRIORITY Increment)
|
IN KPRIORITY Increment)
|
||||||
{
|
{
|
||||||
PLIST_ENTRY WaitEntry, WaitList;
|
PLIST_ENTRY WaitEntry, WaitList;
|
||||||
PKWAIT_BLOCK CurrentWaitBlock;
|
PKWAIT_BLOCK WaitBlock;
|
||||||
PKTHREAD WaitThread;
|
PKTHREAD WaitThread;
|
||||||
|
|
||||||
/* Loop the Wait Entries */
|
/* Loop the Wait Entries */
|
||||||
WaitList = &Event->Header.WaitListHead;
|
WaitList = &Event->Header.WaitListHead;
|
||||||
|
ASSERT(IsListEmpty(&Event->Header.WaitListHead) == FALSE);
|
||||||
WaitEntry = WaitList->Flink;
|
WaitEntry = WaitList->Flink;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Get the current wait block */
|
/* Get the current wait block */
|
||||||
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry,
|
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
|
||||||
KWAIT_BLOCK,
|
|
||||||
WaitListEntry);
|
|
||||||
|
|
||||||
/* Get the waiting thread */
|
/* Get the waiting thread */
|
||||||
WaitThread = CurrentWaitBlock->Thread;
|
WaitThread = WaitBlock->Thread;
|
||||||
|
|
||||||
/* Check the current Wait Mode */
|
/* Check the current Wait Mode */
|
||||||
if (CurrentWaitBlock->WaitType == WaitAny)
|
if (WaitBlock->WaitType == WaitAny)
|
||||||
{
|
{
|
||||||
/* Un-signal it */
|
/* Un-signal it */
|
||||||
Event->Header.SignalState = 0;
|
Event->Header.SignalState = 0;
|
||||||
|
|
||||||
/* Un-signal the event and unwait the thread */
|
/* Un-signal the event and unwait the thread */
|
||||||
KiUnwaitThread(WaitThread, CurrentWaitBlock->WaitKey, Increment);
|
KiUnwaitThread(WaitThread, WaitBlock->WaitKey, Increment);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
/* Unwait the thread with STATUS_KERNEL_APC */
|
||||||
/* Unwait the thread with STATUS_KERNEL_APC */
|
KiUnwaitThread(WaitThread, STATUS_KERNEL_APC, Increment);
|
||||||
KiUnwaitThread(WaitThread, STATUS_KERNEL_APC, Increment);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Next entry */
|
/* Next entry */
|
||||||
WaitEntry = WaitList->Flink;
|
WaitEntry = WaitList->Flink;
|
||||||
|
|
|
@ -42,75 +42,33 @@ FASTCALL
|
||||||
KiWaitTest(IN PVOID ObjectPointer,
|
KiWaitTest(IN PVOID ObjectPointer,
|
||||||
IN KPRIORITY Increment)
|
IN KPRIORITY Increment)
|
||||||
{
|
{
|
||||||
PLIST_ENTRY WaitEntry;
|
PLIST_ENTRY WaitEntry, WaitList;
|
||||||
PLIST_ENTRY WaitList;
|
PKWAIT_BLOCK WaitBlock;
|
||||||
PKWAIT_BLOCK CurrentWaitBlock;
|
|
||||||
PKWAIT_BLOCK NextWaitBlock;
|
|
||||||
PKTHREAD WaitThread;
|
PKTHREAD WaitThread;
|
||||||
PKMUTANT FirstObject = ObjectPointer, Object;
|
PKMUTANT FirstObject = ObjectPointer;
|
||||||
|
NTSTATUS WaitStatus;
|
||||||
|
|
||||||
/* Loop the Wait Entries */
|
/* Loop the Wait Entries */
|
||||||
WaitList = &FirstObject->Header.WaitListHead;
|
WaitList = &FirstObject->Header.WaitListHead;
|
||||||
WaitEntry = WaitList->Flink;
|
WaitEntry = WaitList->Flink;
|
||||||
while ((FirstObject->Header.SignalState > 0) &&
|
while ((FirstObject->Header.SignalState > 0) && (WaitEntry != WaitList))
|
||||||
(WaitEntry != WaitList))
|
|
||||||
{
|
{
|
||||||
/* Get the current wait block */
|
/* Get the current wait block */
|
||||||
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry,
|
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
|
||||||
KWAIT_BLOCK,
|
WaitThread = WaitBlock->Thread;
|
||||||
WaitListEntry);
|
WaitStatus = STATUS_KERNEL_APC;
|
||||||
WaitThread = CurrentWaitBlock->Thread;
|
|
||||||
|
|
||||||
/* Check the current Wait Mode */
|
/* Check the current Wait Mode */
|
||||||
if (CurrentWaitBlock->WaitType == WaitAny)
|
if (WaitBlock->WaitType == WaitAny)
|
||||||
{
|
{
|
||||||
/* Easy case, satisfy only this wait */
|
/* Easy case, satisfy only this wait */
|
||||||
WaitEntry = WaitEntry->Blink;
|
WaitStatus = (NTSTATUS)WaitBlock->WaitKey;
|
||||||
KiSatisfyObjectWait(FirstObject, WaitThread);
|
KiSatisfyObjectWait(FirstObject, WaitThread);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Everything must be satisfied */
|
|
||||||
NextWaitBlock = CurrentWaitBlock->NextWaitBlock;
|
|
||||||
|
|
||||||
/* Loop first to make sure they are valid */
|
/* Now do the rest of the unwait */
|
||||||
while (NextWaitBlock != CurrentWaitBlock)
|
KiUnwaitThread(WaitThread, WaitStatus, Increment);
|
||||||
{
|
WaitEntry = WaitList->Flink;
|
||||||
/* 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +124,7 @@ KiUnwaitThread(IN PKTHREAD Thread,
|
||||||
/* Tell the scheduler do to the increment when it readies the thread */
|
/* Tell the scheduler do to the increment when it readies the thread */
|
||||||
ASSERT(Increment >= 0);
|
ASSERT(Increment >= 0);
|
||||||
Thread->AdjustIncrement = (SCHAR)Increment;
|
Thread->AdjustIncrement = (SCHAR)Increment;
|
||||||
Thread->AdjustReason = 1;
|
Thread->AdjustReason = AdjustUnwait;
|
||||||
|
|
||||||
/* Reschedule the Thread */
|
/* Reschedule the Thread */
|
||||||
KiReadyThread(Thread);
|
KiReadyThread(Thread);
|
||||||
|
|
Loading…
Reference in a new issue