PKWAIT_BLOCK TimerWaitBlock;
PKTIMER ThreadTimer;
PKTHREAD CurrentThread = KeGetCurrentThread();
- NTSTATUS Status;
+ NTSTATUS WaitStatus;
DPRINT("Entering KeDelayExecutionThread\n");
/* Check if the lock is already held */
}
/* Chceck if we can do an alertable wait, if requested */
- if (KiCheckAlertability(Alertable, CurrentThread, WaitMode, &Status)) break;
+ if (KiCheckAlertability(Alertable, CurrentThread, WaitMode, &WaitStatus)) break;
+
+ /* Set status */
+ CurrentThread->WaitStatus = STATUS_WAIT_0;
/* Set Timer */
ThreadTimer = &CurrentThread->Timer;
if (!KiInsertTimer(ThreadTimer, *Interval))
{
/* FIXME: The timer already expired, we should find a new ready thread */
- Status = STATUS_SUCCESS;
+ WaitStatus = STATUS_SUCCESS;
break;
}
/* Find a new thread to run */
DPRINT("Swapping threads\n");
- Status = KiSwapThread();
+ WaitStatus = KiSwapThread();
/* Check if we were executing an APC or if we timed out */
- if (Status != STATUS_KERNEL_APC)
+ if (WaitStatus != STATUS_KERNEL_APC)
{
/* This is a good thing */
- if (Status == STATUS_TIMEOUT) Status = STATUS_SUCCESS;
+ if (WaitStatus == STATUS_TIMEOUT) WaitStatus = STATUS_SUCCESS;
/* Return Status */
- return Status;
+ return WaitStatus;
}
/* FIXME: Fixup interval */
DPRINT("Returning from KeDelayExecutionThread(), %x. Status: %d\n",
KeGetCurrentThread(), Status);
KeReleaseDispatcherDatabaseLock(CurrentThread->WaitIrql);
- return Status;
+ return WaitStatus;
}
/*
PKWAIT_BLOCK TimerWaitBlock;
PKTIMER ThreadTimer;
PKTHREAD CurrentThread = KeGetCurrentThread();
- NTSTATUS Status;
NTSTATUS WaitStatus;
DPRINT("Entering KeWaitForSingleObject\n");
goto SkipWait;
}
- /* Get the current Wait Status */
- WaitStatus = CurrentThread->WaitStatus;
+ /* Set default status */
+ CurrentThread->WaitStatus = STATUS_WAIT_0;
/* Append wait block to the KTHREAD wait block list */
CurrentThread->WaitBlockList = WaitBlock = &CurrentThread->WaitBlock[0];
{
/* It has a normal signal state, so unwait it and return */
KiSatisfyMutantWait(CurrentObject, CurrentThread);
- Status = STATUS_WAIT_0;
+ WaitStatus = CurrentThread->WaitStatus;
goto DontWait;
}
else
{
/* Another satisfied object */
KiSatisfyNonMutantWait(CurrentObject, CurrentThread);
- Status = STATUS_WAIT_0;
+ WaitStatus = STATUS_WAIT_0;
goto DontWait;
}
/* Set up the Wait Block */
WaitBlock->Object = CurrentObject;
WaitBlock->Thread = CurrentThread;
- WaitBlock->WaitKey = (USHORT)(STATUS_WAIT_0);
+ WaitBlock->WaitKey = (USHORT)(STATUS_SUCCESS);
WaitBlock->WaitType = WaitAny;
WaitBlock->NextWaitBlock = WaitBlock;
/* Make sure we can satisfy the Alertable request */
- if (KiCheckAlertability(Alertable, CurrentThread, WaitMode, &Status)) break;
-
- /* Set the Wait Status */
- CurrentThread->WaitStatus = Status;
+ if (KiCheckAlertability(Alertable, CurrentThread, WaitMode, &WaitStatus)) break;
/* Enable the Timeout Timer if there was any specified */
if (Timeout)
if (!Timeout->QuadPart)
{
/* Return a timeout */
- Status = STATUS_TIMEOUT;
+ WaitStatus = STATUS_TIMEOUT;
goto DontWait;
}
if (!KiInsertTimer(ThreadTimer, *Timeout))
{
/* Return a timeout if we couldn't insert the timer */
- Status = STATUS_TIMEOUT;
+ WaitStatus = STATUS_TIMEOUT;
goto DontWait;
}
}
/* Find a new thread to run */
DPRINT("Swapping threads\n");
- Status = KiSwapThread();
+ WaitStatus = KiSwapThread();
/* Check if we were executing an APC */
- if (Status != STATUS_KERNEL_APC)
+ if (WaitStatus != STATUS_KERNEL_APC)
{
/* Return Status */
- return Status;
+ return WaitStatus;
}
/* Check if we had a timeout */
/* Release the Lock, we are done */
DPRINT("Returning from KeWaitForMultipleObjects(), %x. Status: %d\n",
- KeGetCurrentThread(), Status);
+ KeGetCurrentThread(), WaitStatus);
KeReleaseDispatcherDatabaseLock(CurrentThread->WaitIrql);
- return Status;
+ return WaitStatus;
DontWait:
/* Adjust the Quantum */
/* Release & Return */
DPRINT("Quick-return from KeWaitForMultipleObjects(), %x. Status: %d\n.",
- KeGetCurrentThread(), Status);
+ KeGetCurrentThread(), WaitStatus);
KeReleaseDispatcherDatabaseLock(CurrentThread->WaitIrql);
- return Status;
+ return WaitStatus;
}
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS
+STDCALL
KeWaitForMultipleObjects(ULONG Count,
PVOID Object[],
WAIT_TYPE WaitType,
PKTHREAD CurrentThread = KeGetCurrentThread();
ULONG AllObjectsSignaled;
ULONG WaitIndex;
- NTSTATUS Status;
NTSTATUS WaitStatus;
DPRINT("Entering KeWaitForMultipleObjects(Count %lu Object[] %p) "
"PsGetCurrentThread() %x, Timeout %x\n",
goto SkipWait;
}
- /* Get the current Wait Status */
- WaitStatus = CurrentThread->WaitStatus;
-
/* Append wait block to the KTHREAD wait block list */
CurrentThread->WaitBlockList = WaitBlock = WaitBlockArray;
+ /* Set default wait status */
+ CurrentThread->WaitStatus = STATUS_WAIT_0;
+
/* Check if the wait is (already) satisfied */
AllObjectsSignaled = TRUE;
{
/* Normal signal state, so unwait it and return */
KiSatisfyMutantWait(CurrentObject, CurrentThread);
- Status = STATUS_WAIT_0 | WaitIndex;
+ WaitStatus = CurrentThread->WaitStatus | WaitIndex;
goto DontWait;
}
else
{
/* Another signaled object, unwait and return */
KiSatisfyNonMutantWait(CurrentObject, CurrentThread);
- Status = WaitIndex;
+ WaitStatus = WaitIndex;
goto DontWait;
}
}
/* Satisfy their Waits and return to the caller */
KiSatisifyMultipleObjectWaits(WaitBlock);
- Status = STATUS_WAIT_0;
+ WaitStatus = CurrentThread->WaitStatus;
goto DontWait;
}
/* Make sure we can satisfy the Alertable request */
- if (KiCheckAlertability(Alertable, CurrentThread, WaitMode, &Status)) break;
-
- /* Set the Wait Status */
- CurrentThread->WaitStatus = Status;
+ if (KiCheckAlertability(Alertable, CurrentThread, WaitMode, &WaitStatus)) break;
/* Enable the Timeout Timer if there was any specified */
if (Timeout)
if (!Timeout->QuadPart)
{
/* Return a timeout */
- Status = STATUS_TIMEOUT;
+ WaitStatus = STATUS_TIMEOUT;
goto DontWait;
}
if (!KiInsertTimer(ThreadTimer, *Timeout))
{
/* Return a timeout if we couldn't insert the timer */
- Status = STATUS_TIMEOUT;
+ WaitStatus = STATUS_TIMEOUT;
goto DontWait;
}
}
/* Find a new thread to run */
DPRINT("Swapping threads\n");
- Status = KiSwapThread();
+ WaitStatus = KiSwapThread();
/* Check if we were executing an APC */
DPRINT("Thread is back\n");
- if (Status != STATUS_KERNEL_APC)
+ if (WaitStatus != STATUS_KERNEL_APC)
{
/* Return Status */
- return Status;
+ return WaitStatus;
}
/* Check if we had a timeout */
while (TRUE);
/* Release the Lock, we are done */
- DPRINT("Returning, %x. Status: %d\n", KeGetCurrentThread(), Status);
+ DPRINT("Returning, %x. Status: %d\n", KeGetCurrentThread(), WaitStatus);
KeReleaseDispatcherDatabaseLock(CurrentThread->WaitIrql);
- return Status;
+ return WaitStatus;
DontWait:
/* Adjust the Quantum */
/* Release & Return */
DPRINT("Returning, %x. Status: %d\n. We did not wait.",
- KeGetCurrentThread(), Status);
+ KeGetCurrentThread(), WaitStatus);
KeReleaseDispatcherDatabaseLock(CurrentThread->WaitIrql);
- return Status;
+ return WaitStatus;
}
VOID