TimerWaitBlock->Thread = CurrentThread;
TimerWaitBlock->WaitKey = (USHORT)STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
- TimerWaitBlock->NextWaitBlock = NULL;
+ TimerWaitBlock->NextWaitBlock = TimerWaitBlock;
/* Link the timer to this Wait Block */
InitializeListHead(&ThreadTimer->Header.WaitListHead);
WaitBlock->Thread = CurrentThread;
WaitBlock->WaitKey = (USHORT)(STATUS_WAIT_0);
WaitBlock->WaitType = WaitAny;
- WaitBlock->NextWaitBlock = NULL;
+ WaitBlock->NextWaitBlock = WaitBlock;
/* Make sure we can satisfy the Alertable request */
KiCheckAlertability(Alertable, CurrentThread, WaitMode, &Status);
TimerWaitBlock->Thread = CurrentThread;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
- TimerWaitBlock->NextWaitBlock = NULL;
+ TimerWaitBlock->NextWaitBlock = WaitBlock;
/* Link the timer to this Wait Block */
InitializeListHead(&ThreadTimer->Header.WaitListHead);
/* Check in regards to the Thread Object Limit */
if (Count > THREAD_WAIT_OBJECTS) {
- DPRINT1("(%s:%d) Too many objects!\n", __FILE__, __LINE__);
KEBUGCHECK(MAXIMUM_WAIT_OBJECTS_EXCEEDED);
}
/* Using our own Block Array. Check in regards to System Object Limit */
if (Count > MAXIMUM_WAIT_OBJECTS) {
- DPRINT1("(%s:%d) Too many objects!\n", __FILE__, __LINE__);
KEBUGCHECK(MAXIMUM_WAIT_OBJECTS_EXCEEDED);
}
}
/* Return to the Root Wait Block */
WaitBlock--;
- WaitBlock->NextWaitBlock = NULL;
+ WaitBlock->NextWaitBlock = WaitBlockArray;
/* Check if this is a Wait All and all the objects are signaled */
if ((WaitType == WaitAll) && (AllObjectsSignaled)) {
TimerWaitBlock->Thread = CurrentThread;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
- TimerWaitBlock->NextWaitBlock = NULL;
+ TimerWaitBlock->NextWaitBlock = WaitBlockArray;
/* Link the timer to this Wait Block */
InitializeListHead(&ThreadTimer->Header.WaitListHead);
/* Insert into Object's Wait List*/
WaitBlock = CurrentThread->WaitBlockList;
- while (WaitBlock) {
+ do {
/* Get the Current Object */
CurrentObject = WaitBlock->Object;
/* Move to the next Wait Block */
WaitBlock = WaitBlock->NextWaitBlock;
- }
+ } while (WaitBlock != WaitBlockArray);
/* Handle Kernel Queues */
if (CurrentThread->Queue) {
PLIST_ENTRY WaitList;
PKWAIT_BLOCK CurrentWaitBlock;
PKWAIT_BLOCK NextWaitBlock;
+ PKTHREAD WaitThread;
/* Loop the Wait Entries */
DPRINT("KiWaitTest for Object: %x\n", Object);
/* Get the current wait block */
CurrentWaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
+ WaitThread = CurrentWaitBlock->Thread;
/* Check the current Wait Mode */
if (CurrentWaitBlock->WaitType == WaitAny) {
/* Easy case, satisfy only this wait */
DPRINT("Satisfiying a Wait any\n");
WaitEntry = WaitEntry->Blink;
- KiSatisfyObjectWait(Object, CurrentWaitBlock->Thread);
+ KiSatisfyObjectWait(Object, WaitThread);
} else {
NextWaitBlock = CurrentWaitBlock->NextWaitBlock;
/* Loop first to make sure they are valid */
- while (NextWaitBlock) {
+ while (NextWaitBlock != CurrentWaitBlock) {
/* Check if the object is signaled */
- if (!KiIsObjectSignaled(Object, CurrentWaitBlock->Thread)) {
+ DPRINT("Checking: %x %d\n", NextWaitBlock->Object, Object->SignalState);
+ if (!KiIsObjectSignaled(NextWaitBlock->Object, WaitThread)) {
/* It's not, move to the next one */
- DPRINT1("One of the object is non-signaled, sorry.\n");
+ DPRINT("One of the object is non-signaled, sorry.\n");
goto SkipUnwait;
}
/* All waits satisfied, unwait the thread */
DPRINT("Unwaiting the Thread\n");
- KiAbortWaitThread(CurrentWaitBlock->Thread, CurrentWaitBlock->WaitKey, Increment);
+ KiAbortWaitThread(WaitThread, CurrentWaitBlock->WaitKey, Increment);
SkipUnwait:
/* Next entry */
/* Remove the Wait Blocks from the list */
DPRINT("Removing waits\n");
WaitBlock = Thread->WaitBlockList;
- while (WaitBlock) {
+ do {
/* Remove it */
DPRINT("Removing Waitblock: %x, %x\n", WaitBlock, WaitBlock->NextWaitBlock);
/* Go to the next one */
WaitBlock = WaitBlock->NextWaitBlock;
- };
+ } while (WaitBlock != Thread->WaitBlockList);
/* Check if there's a Thread Timer */
if (Thread->Timer.Header.Inserted) {
FASTCALL
KiSatisifyMultipleObjectWaits(PKWAIT_BLOCK WaitBlock)
{
+ PKWAIT_BLOCK FirstBlock = WaitBlock;
PKTHREAD WaitThread = WaitBlock->Thread;
/* Loop through all the Wait Blocks, and wake each Object */
- while (WaitBlock) {
+ do {
/* Wake the Object */
KiSatisfyObjectWait(WaitBlock->Object, WaitThread);
WaitBlock = WaitBlock->NextWaitBlock;
- }
+ } while (WaitBlock != FirstBlock);
}
VOID