Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
/*
|
2005-11-19 22:13:35 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
2006-07-13 21:48:45 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2005-01-26 13:58:37 +00:00
|
|
|
* FILE: ntoskrnl/ke/wait.c
|
2006-01-05 04:26:55 +00:00
|
|
|
* PURPOSE: Manages waiting for Dispatcher Objects
|
2006-07-13 21:48:45 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2005-11-19 22:13:35 +00:00
|
|
|
* Gunnar Dalsnes
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
#define NDEBUG
|
2007-01-23 22:46:38 +00:00
|
|
|
#include <debug.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2006-01-10 21:36:42 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2006-07-13 21:48:45 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-07-13 22:19:57 +00:00
|
|
|
KiWaitTest(IN PVOID ObjectPointer,
|
|
|
|
IN KPRIORITY Increment)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2007-01-16 02:24:19 +00:00
|
|
|
PLIST_ENTRY WaitEntry, WaitList;
|
|
|
|
PKWAIT_BLOCK WaitBlock;
|
2006-07-13 21:48:45 +00:00
|
|
|
PKTHREAD WaitThread;
|
2007-01-16 02:24:19 +00:00
|
|
|
PKMUTANT FirstObject = ObjectPointer;
|
|
|
|
NTSTATUS WaitStatus;
|
2006-07-13 21:48:45 +00:00
|
|
|
|
|
|
|
/* Loop the Wait Entries */
|
|
|
|
WaitList = &FirstObject->Header.WaitListHead;
|
|
|
|
WaitEntry = WaitList->Flink;
|
2007-01-16 02:24:19 +00:00
|
|
|
while ((FirstObject->Header.SignalState > 0) && (WaitEntry != WaitList))
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
|
|
|
/* Get the current wait block */
|
2007-01-16 02:24:19 +00:00
|
|
|
WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
|
|
|
|
WaitThread = WaitBlock->Thread;
|
|
|
|
WaitStatus = STATUS_KERNEL_APC;
|
2006-07-13 21:48:45 +00:00
|
|
|
|
|
|
|
/* Check the current Wait Mode */
|
2007-01-16 02:24:19 +00:00
|
|
|
if (WaitBlock->WaitType == WaitAny)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
|
|
|
/* Easy case, satisfy only this wait */
|
2007-01-16 02:24:19 +00:00
|
|
|
WaitStatus = (NTSTATUS)WaitBlock->WaitKey;
|
2006-07-13 21:48:45 +00:00
|
|
|
KiSatisfyObjectWait(FirstObject, WaitThread);
|
|
|
|
}
|
|
|
|
|
2007-01-16 02:24:19 +00:00
|
|
|
/* Now do the rest of the unwait */
|
|
|
|
KiUnwaitThread(WaitThread, WaitStatus, Increment);
|
|
|
|
WaitEntry = WaitList->Flink;
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-09-14 03:49:20 +00:00
|
|
|
KiUnlinkThread(IN PKTHREAD Thread,
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
IN LONG_PTR WaitStatus)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
|
|
|
PKWAIT_BLOCK WaitBlock;
|
2006-07-13 22:19:57 +00:00
|
|
|
PKTIMER Timer;
|
2006-07-13 21:48:45 +00:00
|
|
|
|
2006-07-13 22:19:57 +00:00
|
|
|
/* Update wait status */
|
|
|
|
Thread->WaitStatus |= WaitStatus;
|
2006-07-13 21:48:45 +00:00
|
|
|
|
|
|
|
/* Remove the Wait Blocks from the list */
|
|
|
|
WaitBlock = Thread->WaitBlockList;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Remove it */
|
|
|
|
RemoveEntryList(&WaitBlock->WaitListEntry);
|
|
|
|
|
|
|
|
/* Go to the next one */
|
|
|
|
WaitBlock = WaitBlock->NextWaitBlock;
|
|
|
|
} while (WaitBlock != Thread->WaitBlockList);
|
|
|
|
|
2006-07-14 01:03:27 +00:00
|
|
|
/* Remove the thread from the wait list! */
|
|
|
|
if (Thread->WaitListEntry.Flink) RemoveEntryList(&Thread->WaitListEntry);
|
2006-07-13 22:19:57 +00:00
|
|
|
|
2006-07-13 21:48:45 +00:00
|
|
|
/* Check if there's a Thread Timer */
|
2006-07-13 22:19:57 +00:00
|
|
|
Timer = &Thread->Timer;
|
2007-01-24 06:50:28 +00:00
|
|
|
if (Timer->Header.Inserted) KxRemoveTreeTimer(Timer);
|
2006-07-13 21:48:45 +00:00
|
|
|
|
|
|
|
/* Increment the Queue's active threads */
|
2006-07-13 22:19:57 +00:00
|
|
|
if (Thread->Queue) Thread->Queue->CurrentCount++;
|
2006-09-14 03:49:20 +00:00
|
|
|
}
|
2006-07-13 21:48:45 +00:00
|
|
|
|
2006-09-14 03:49:20 +00:00
|
|
|
/* Must be called with the dispatcher lock held */
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KiUnwaitThread(IN PKTHREAD Thread,
|
2010-01-13 22:35:43 +00:00
|
|
|
IN LONG_PTR WaitStatus,
|
2006-09-14 03:49:20 +00:00
|
|
|
IN KPRIORITY Increment)
|
|
|
|
{
|
|
|
|
/* Unlink the thread */
|
|
|
|
KiUnlinkThread(Thread, WaitStatus);
|
2006-07-13 22:52:18 +00:00
|
|
|
|
2006-09-14 03:49:20 +00:00
|
|
|
/* Tell the scheduler do to the increment when it readies the thread */
|
|
|
|
ASSERT(Increment >= 0);
|
|
|
|
Thread->AdjustIncrement = (SCHAR)Increment;
|
2007-01-16 02:24:19 +00:00
|
|
|
Thread->AdjustReason = AdjustUnwait;
|
2006-07-13 22:52:18 +00:00
|
|
|
|
2006-07-13 21:48:45 +00:00
|
|
|
/* Reschedule the Thread */
|
2006-07-13 22:52:18 +00:00
|
|
|
KiReadyThread(Thread);
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KiAcquireFastMutex(IN PFAST_MUTEX FastMutex)
|
|
|
|
{
|
|
|
|
/* Increase contention count */
|
|
|
|
FastMutex->Contention++;
|
|
|
|
|
|
|
|
/* Wait for the event */
|
2010-03-03 16:03:14 +00:00
|
|
|
KeWaitForSingleObject(&FastMutex->Event,
|
2006-07-13 21:48:45 +00:00
|
|
|
WrMutex,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KiAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
|
|
|
|
{
|
|
|
|
ULONG BitsToRemove, BitsToAdd;
|
|
|
|
LONG OldValue, NewValue;
|
2009-08-21 15:57:26 +00:00
|
|
|
|
|
|
|
/* We depend on these bits being just right */
|
|
|
|
C_ASSERT((GM_LOCK_WAITER_WOKEN * 2) == GM_LOCK_WAITER_INC);
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Increase the contention count */
|
|
|
|
GuardedMutex->Contention++;
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Start by unlocking the Guarded Mutex */
|
|
|
|
BitsToRemove = GM_LOCK_BIT;
|
|
|
|
BitsToAdd = GM_LOCK_WAITER_INC;
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Start change loop */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Loop sanity checks */
|
|
|
|
ASSERT((BitsToRemove == GM_LOCK_BIT) ||
|
|
|
|
(BitsToRemove == (GM_LOCK_BIT | GM_LOCK_WAITER_WOKEN)));
|
|
|
|
ASSERT((BitsToAdd == GM_LOCK_WAITER_INC) ||
|
|
|
|
(BitsToAdd == GM_LOCK_WAITER_WOKEN));
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Get the Count Bits */
|
|
|
|
OldValue = GuardedMutex->Count;
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Start internal bit change loop */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Check if the Guarded Mutex is locked */
|
|
|
|
if (OldValue & GM_LOCK_BIT)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT((BitsToRemove == GM_LOCK_BIT) ||
|
|
|
|
((OldValue & GM_LOCK_WAITER_WOKEN) != 0));
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Unlock it by removing the Lock Bit */
|
|
|
|
NewValue = OldValue ^ BitsToRemove;
|
|
|
|
NewValue = InterlockedCompareExchange(&GuardedMutex->Count,
|
|
|
|
NewValue,
|
|
|
|
OldValue);
|
|
|
|
if (NewValue == OldValue) return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The Guarded Mutex isn't locked, so simply set the bits */
|
|
|
|
NewValue = OldValue + BitsToAdd;
|
|
|
|
NewValue = InterlockedCompareExchange(&GuardedMutex->Count,
|
|
|
|
NewValue,
|
|
|
|
OldValue);
|
|
|
|
if (NewValue == OldValue) break;
|
|
|
|
}
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Old value changed, loop again */
|
|
|
|
OldValue = NewValue;
|
|
|
|
}
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Now we have to wait for it */
|
|
|
|
KeWaitForGate(&GuardedMutex->Gate, WrGuardedMutex, KernelMode);
|
|
|
|
ASSERT((GuardedMutex->Count & GM_LOCK_WAITER_WOKEN) != 0);
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
/* Ok, the wait is done, so set the new bits */
|
|
|
|
BitsToRemove = GM_LOCK_BIT | GM_LOCK_WAITER_WOKEN;
|
|
|
|
BitsToAdd = GM_LOCK_WAITER_WOKEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-11 05:26:38 +00:00
|
|
|
//
|
|
|
|
// This routine exits the dispatcher after a compatible operation and
|
|
|
|
// swaps the context to the next scheduled thread on the current CPU if
|
|
|
|
// one is available.
|
|
|
|
//
|
|
|
|
// It does NOT attempt to scan for a new thread to schedule.
|
|
|
|
//
|
2006-07-13 21:48:45 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-07-13 22:19:57 +00:00
|
|
|
KiExitDispatcher(IN KIRQL OldIrql)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2006-09-11 05:26:38 +00:00
|
|
|
PKPRCB Prcb = KeGetCurrentPrcb();
|
|
|
|
PKTHREAD Thread, NextThread;
|
|
|
|
BOOLEAN PendingApc;
|
|
|
|
|
|
|
|
/* Make sure we're at synchronization level */
|
2007-01-23 22:46:38 +00:00
|
|
|
ASSERT(KeGetCurrentIrql() == SYNCH_LEVEL);
|
2006-09-11 05:26:38 +00:00
|
|
|
|
|
|
|
/* Check if we have deferred threads */
|
|
|
|
KiCheckDeferredReadyList(Prcb);
|
|
|
|
|
|
|
|
/* Check if we were called at dispatcher level or higher */
|
|
|
|
if (OldIrql >= DISPATCH_LEVEL)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2006-09-11 05:26:38 +00:00
|
|
|
/* Check if we have a thread to schedule, and that no DPC is active */
|
|
|
|
if ((Prcb->NextThread) && !(Prcb->DpcRoutineActive))
|
|
|
|
{
|
|
|
|
/* Request DPC interrupt */
|
|
|
|
HalRequestSoftwareInterrupt(DISPATCH_LEVEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lower IRQL and exit */
|
|
|
|
goto Quickie;
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
2006-09-11 05:26:38 +00:00
|
|
|
|
|
|
|
/* Make sure there's a new thread scheduled */
|
|
|
|
if (!Prcb->NextThread) goto Quickie;
|
|
|
|
|
|
|
|
/* Lock the PRCB */
|
|
|
|
KiAcquirePrcbLock(Prcb);
|
|
|
|
|
|
|
|
/* Get the next and current threads now */
|
|
|
|
NextThread = Prcb->NextThread;
|
|
|
|
Thread = Prcb->CurrentThread;
|
|
|
|
|
|
|
|
/* Set current thread's swap busy to true */
|
|
|
|
KiSetThreadSwapBusy(Thread);
|
|
|
|
|
|
|
|
/* Switch threads in PRCB */
|
|
|
|
Prcb->NextThread = NULL;
|
|
|
|
Prcb->CurrentThread = NextThread;
|
|
|
|
|
|
|
|
/* Set thread to running */
|
|
|
|
NextThread->State = Running;
|
|
|
|
|
|
|
|
/* Queue it on the ready lists */
|
|
|
|
KxQueueReadyThread(Thread, Prcb);
|
|
|
|
|
|
|
|
/* Set wait IRQL */
|
|
|
|
Thread->WaitIrql = OldIrql;
|
|
|
|
|
|
|
|
/* Swap threads and check if APCs were pending */
|
2010-11-08 11:56:22 +00:00
|
|
|
PendingApc = KiSwapContext(OldIrql, Thread);
|
2006-09-11 05:26:38 +00:00
|
|
|
if (PendingApc)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2006-09-11 05:26:38 +00:00
|
|
|
/* Lower only to APC */
|
|
|
|
KeLowerIrql(APC_LEVEL);
|
|
|
|
|
|
|
|
/* Deliver APCs */
|
|
|
|
KiDeliverApc(KernelMode, NULL, NULL);
|
|
|
|
ASSERT(OldIrql == PASSIVE_LEVEL);
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
|
|
|
|
2006-09-11 05:26:38 +00:00
|
|
|
/* Lower IRQl back */
|
|
|
|
Quickie:
|
2006-07-13 21:48:45 +00:00
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
2015-09-08 20:14:39 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KeIsWaitListEmpty(IN PVOID Object)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-14 05:36:04 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2006-07-13 21:48:45 +00:00
|
|
|
NTAPI
|
|
|
|
KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode,
|
|
|
|
IN BOOLEAN Alertable,
|
|
|
|
IN PLARGE_INTEGER Interval OPTIONAL)
|
2005-02-14 05:36:04 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
PKTIMER Timer;
|
|
|
|
PKWAIT_BLOCK TimerBlock;
|
2006-09-14 15:48:02 +00:00
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
|
|
|
NTSTATUS WaitStatus;
|
2006-07-14 01:03:27 +00:00
|
|
|
BOOLEAN Swappable;
|
2007-01-23 18:39:47 +00:00
|
|
|
PLARGE_INTEGER OriginalDueTime;
|
|
|
|
LARGE_INTEGER DueTime, NewDueTime, InterruptTime;
|
2007-01-24 06:50:28 +00:00
|
|
|
ULONG Hand = 0;
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
|
2014-03-30 21:10:04 +00:00
|
|
|
if (Thread->WaitNext)
|
|
|
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
|
|
|
else
|
|
|
|
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
|
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* If this is a user-mode wait of 0 seconds, yield execution */
|
|
|
|
if (!(Interval->QuadPart) && (WaitMode != KernelMode))
|
2006-01-05 04:26:55 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Make sure the wait isn't alertable or interrupting an APC */
|
|
|
|
if (!(Alertable) && !(Thread->ApcState.UserApcPending))
|
|
|
|
{
|
|
|
|
/* Yield execution */
|
2014-03-30 21:10:04 +00:00
|
|
|
return NtYieldExecution();
|
2007-01-23 18:39:47 +00:00
|
|
|
}
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Setup the original time and timer/wait blocks */
|
|
|
|
OriginalDueTime = Interval;
|
|
|
|
Timer = &Thread->Timer;
|
|
|
|
TimerBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if the lock is already held */
|
|
|
|
if (!Thread->WaitNext) goto WaitStart;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Otherwise, we already have the lock, so initialize the wait */
|
|
|
|
Thread->WaitNext = FALSE;
|
|
|
|
KxDelayThreadWait();
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Start wait loop */
|
|
|
|
for (;;)
|
2006-09-14 15:48:02 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Disable pre-emption */
|
|
|
|
Thread->Preempted = FALSE;
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if a kernel APC is pending and we're below APC_LEVEL */
|
|
|
|
if ((Thread->ApcState.KernelApcPending) && !(Thread->SpecialApcDisable) &&
|
|
|
|
(Thread->WaitIrql < APC_LEVEL))
|
|
|
|
{
|
|
|
|
/* Unlock the dispatcher */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check if we have to bail out due to an alerted state */
|
|
|
|
WaitStatus = KiCheckAlertability(Thread, Alertable, WaitMode);
|
|
|
|
if (WaitStatus != STATUS_WAIT_0) break;
|
2006-07-22 17:19:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if the timer expired */
|
|
|
|
InterruptTime.QuadPart = KeQueryInterruptTime();
|
2007-01-23 22:46:38 +00:00
|
|
|
if ((ULONGLONG)InterruptTime.QuadPart >= Timer->DueTime.QuadPart)
|
2007-01-23 18:39:47 +00:00
|
|
|
{
|
|
|
|
/* It did, so we don't need to wait */
|
|
|
|
goto NoWait;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* It didn't, so activate it */
|
|
|
|
Timer->Header.Inserted = TRUE;
|
2006-01-06 08:00:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Handle Kernel Queues */
|
|
|
|
if (Thread->Queue) KiActivateWaiterQueue(Thread->Queue);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Setup the wait information */
|
|
|
|
Thread->State = Waiting;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Add the thread to the wait list */
|
|
|
|
KiAddThreadToWaitList(Thread, Swappable);
|
|
|
|
|
|
|
|
/* Insert the timer and swap the thread */
|
|
|
|
ASSERT(Thread->WaitIrql <= DISPATCH_LEVEL);
|
|
|
|
KiSetThreadSwapBusy(Thread);
|
2007-01-24 06:50:28 +00:00
|
|
|
KxInsertTimer(Timer, Hand);
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
WaitStatus = (NTSTATUS)KiSwapThread(Thread, KeGetCurrentPrcb());
|
2007-01-23 18:39:47 +00:00
|
|
|
|
|
|
|
/* Check if were swapped ok */
|
|
|
|
if (WaitStatus != STATUS_KERNEL_APC)
|
|
|
|
{
|
|
|
|
/* This is a good thing */
|
|
|
|
if (WaitStatus == STATUS_TIMEOUT) WaitStatus = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* Return Status */
|
|
|
|
return WaitStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recalculate due times */
|
|
|
|
Interval = KiRecalculateDueTime(OriginalDueTime,
|
|
|
|
&DueTime,
|
|
|
|
&NewDueTime);
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
WaitStart:
|
|
|
|
/* Setup a new wait */
|
|
|
|
Thread->WaitIrql = KeRaiseIrqlToSynchLevel();
|
|
|
|
KxDelayThreadWait();
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2007-01-23 18:39:47 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* We're done! */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
2006-01-06 08:37:46 +00:00
|
|
|
return WaitStatus;
|
2007-01-23 18:39:47 +00:00
|
|
|
|
|
|
|
NoWait:
|
|
|
|
/* There was nothing to wait for. Did we have a wait interval? */
|
|
|
|
if (!Interval->QuadPart)
|
|
|
|
{
|
|
|
|
/* Unlock the dispatcher and do a yield */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
return NtYieldExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlock the dispatcher and adjust the quantum for a no-wait */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2007-01-23 18:39:47 +00:00
|
|
|
KiAdjustQuantumThread(Thread);
|
|
|
|
return STATUS_SUCCESS;
|
2005-02-14 05:36:04 +00:00
|
|
|
}
|
1999-09-08 23:51:36 +00:00
|
|
|
|
2003-07-10 17:44:06 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
1998-09-05 17:34:23 +00:00
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2006-07-13 21:48:45 +00:00
|
|
|
NTAPI
|
2006-07-14 21:45:27 +00:00
|
|
|
KeWaitForSingleObject(IN PVOID Object,
|
|
|
|
IN KWAIT_REASON WaitReason,
|
|
|
|
IN KPROCESSOR_MODE WaitMode,
|
|
|
|
IN BOOLEAN Alertable,
|
|
|
|
IN PLARGE_INTEGER Timeout OPTIONAL)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2006-09-14 15:48:02 +00:00
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
2007-01-23 18:39:47 +00:00
|
|
|
PKMUTANT CurrentObject = (PKMUTANT)Object;
|
|
|
|
PKWAIT_BLOCK WaitBlock = &Thread->WaitBlock[0];
|
|
|
|
PKWAIT_BLOCK TimerBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
|
|
|
|
PKTIMER Timer = &Thread->Timer;
|
2006-09-14 15:48:02 +00:00
|
|
|
NTSTATUS WaitStatus;
|
2006-07-14 01:03:27 +00:00
|
|
|
BOOLEAN Swappable;
|
2011-06-12 21:15:33 +00:00
|
|
|
LARGE_INTEGER DueTime = {{0}}, NewDueTime, InterruptTime;
|
2006-07-22 17:19:09 +00:00
|
|
|
PLARGE_INTEGER OriginalDueTime = Timeout;
|
2007-01-24 06:50:28 +00:00
|
|
|
ULONG Hand = 0;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2012-06-19 10:43:38 +00:00
|
|
|
if (Thread->WaitNext)
|
2019-05-30 13:44:56 +00:00
|
|
|
ASSERT(KeGetCurrentIrql() == SYNCH_LEVEL);
|
2012-06-19 10:43:38 +00:00
|
|
|
else
|
|
|
|
ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL ||
|
|
|
|
(KeGetCurrentIrql() == DISPATCH_LEVEL &&
|
|
|
|
Timeout && Timeout->QuadPart == 0));
|
2012-06-19 08:24:32 +00:00
|
|
|
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
/* Check if the lock is already held */
|
2007-01-23 18:39:47 +00:00
|
|
|
if (!Thread->WaitNext) goto WaitStart;
|
2006-01-06 08:00:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Otherwise, we already have the lock, so initialize the wait */
|
|
|
|
Thread->WaitNext = FALSE;
|
|
|
|
KxSingleThreadWait();
|
2006-01-05 04:26:55 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Start wait loop */
|
|
|
|
for (;;)
|
2006-09-14 15:48:02 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Disable pre-emption */
|
|
|
|
Thread->Preempted = FALSE;
|
|
|
|
|
|
|
|
/* Check if a kernel APC is pending and we're below APC_LEVEL */
|
|
|
|
if ((Thread->ApcState.KernelApcPending) && !(Thread->SpecialApcDisable) &&
|
|
|
|
(Thread->WaitIrql < APC_LEVEL))
|
|
|
|
{
|
|
|
|
/* Unlock the dispatcher */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
}
|
|
|
|
else
|
2006-09-14 15:48:02 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(CurrentObject->Header.Type != QueueObject);
|
|
|
|
|
|
|
|
/* Check if it's a mutant */
|
|
|
|
if (CurrentObject->Header.Type == MutantObject)
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check its signal state or if we own it */
|
|
|
|
if ((CurrentObject->Header.SignalState > 0) ||
|
|
|
|
(Thread == CurrentObject->OwnerThread))
|
|
|
|
{
|
|
|
|
/* Just unwait this guy and exit */
|
2021-06-29 08:57:43 +00:00
|
|
|
if (CurrentObject->Header.SignalState != MINLONG)
|
2007-01-23 18:39:47 +00:00
|
|
|
{
|
|
|
|
/* It has a normal signal state. Unwait and return */
|
|
|
|
KiSatisfyMutantWait(CurrentObject, Thread);
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
WaitStatus = (NTSTATUS)Thread->WaitStatus;
|
2007-01-23 18:39:47 +00:00
|
|
|
goto DontWait;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Raise an exception */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
ExRaiseStatus(STATUS_MUTANT_LIMIT_EXCEEDED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CurrentObject->Header.SignalState > 0)
|
|
|
|
{
|
|
|
|
/* Another satisfied object */
|
2007-01-23 22:46:38 +00:00
|
|
|
KiSatisfyNonMutantWait(CurrentObject);
|
2007-01-23 18:39:47 +00:00
|
|
|
WaitStatus = STATUS_WAIT_0;
|
2006-07-13 21:48:45 +00:00
|
|
|
goto DontWait;
|
|
|
|
}
|
2007-01-23 18:39:47 +00:00
|
|
|
|
|
|
|
/* Make sure we can satisfy the Alertable request */
|
|
|
|
WaitStatus = KiCheckAlertability(Thread, Alertable, WaitMode);
|
|
|
|
if (WaitStatus != STATUS_WAIT_0) break;
|
|
|
|
|
|
|
|
/* Enable the Timeout Timer if there was any specified */
|
|
|
|
if (Timeout)
|
2006-01-05 04:26:55 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if the timer expired */
|
|
|
|
InterruptTime.QuadPart = KeQueryInterruptTime();
|
2007-01-23 22:46:38 +00:00
|
|
|
if ((ULONGLONG)InterruptTime.QuadPart >=
|
|
|
|
Timer->DueTime.QuadPart)
|
2007-01-23 18:39:47 +00:00
|
|
|
{
|
|
|
|
/* It did, so we don't need to wait */
|
|
|
|
WaitStatus = STATUS_TIMEOUT;
|
|
|
|
goto DontWait;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* It didn't, so activate it */
|
|
|
|
Timer->Header.Inserted = TRUE;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Link the Object to this Wait Block */
|
|
|
|
InsertTailList(&CurrentObject->Header.WaitListHead,
|
|
|
|
&WaitBlock->WaitListEntry);
|
2005-02-28 16:44:38 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Handle Kernel Queues */
|
|
|
|
if (Thread->Queue) KiActivateWaiterQueue(Thread->Queue);
|
2006-07-22 17:19:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Setup the wait information */
|
|
|
|
Thread->State = Waiting;
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Add the thread to the wait list */
|
|
|
|
KiAddThreadToWaitList(Thread, Swappable);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Activate thread swap */
|
|
|
|
ASSERT(Thread->WaitIrql <= DISPATCH_LEVEL);
|
|
|
|
KiSetThreadSwapBusy(Thread);
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we have a timer */
|
|
|
|
if (Timeout)
|
|
|
|
{
|
|
|
|
/* Insert it */
|
2007-01-24 06:50:28 +00:00
|
|
|
KxInsertTimer(Timer, Hand);
|
2007-01-23 18:39:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, unlock the dispatcher */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2007-01-23 18:39:47 +00:00
|
|
|
}
|
2006-01-06 08:00:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Do the actual swap */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
WaitStatus = (NTSTATUS)KiSwapThread(Thread, KeGetCurrentPrcb());
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we were executing an APC */
|
|
|
|
if (WaitStatus != STATUS_KERNEL_APC) return WaitStatus;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we had a timeout */
|
|
|
|
if (Timeout)
|
|
|
|
{
|
|
|
|
/* Recalculate due times */
|
|
|
|
Timeout = KiRecalculateDueTime(OriginalDueTime,
|
|
|
|
&DueTime,
|
|
|
|
&NewDueTime);
|
|
|
|
}
|
2006-01-06 08:00:09 +00:00
|
|
|
}
|
2007-01-23 18:39:47 +00:00
|
|
|
WaitStart:
|
|
|
|
/* Setup a new wait */
|
|
|
|
Thread->WaitIrql = KeRaiseIrqlToSynchLevel();
|
|
|
|
KxSingleThreadWait();
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2006-09-14 15:48:02 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-14 15:48:02 +00:00
|
|
|
/* Wait complete */
|
2007-01-23 18:39:47 +00:00
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
2006-01-06 08:37:46 +00:00
|
|
|
return WaitStatus;
|
2005-07-30 23:43:45 +00:00
|
|
|
|
|
|
|
DontWait:
|
2007-01-17 20:44:37 +00:00
|
|
|
/* Release dispatcher lock but maintain high IRQL */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2005-07-30 23:43:45 +00:00
|
|
|
|
2007-01-17 20:44:37 +00:00
|
|
|
/* Adjust the Quantum and return the wait status */
|
|
|
|
KiAdjustQuantumThread(Thread);
|
2006-01-06 08:37:46 +00:00
|
|
|
return WaitStatus;
|
2004-06-05 18:52:35 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 17:44:06 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-01-06 08:37:46 +00:00
|
|
|
NTSTATUS
|
2006-07-13 21:48:45 +00:00
|
|
|
NTAPI
|
|
|
|
KeWaitForMultipleObjects(IN ULONG Count,
|
|
|
|
IN PVOID Object[],
|
|
|
|
IN WAIT_TYPE WaitType,
|
|
|
|
IN KWAIT_REASON WaitReason,
|
|
|
|
IN KPROCESSOR_MODE WaitMode,
|
|
|
|
IN BOOLEAN Alertable,
|
|
|
|
IN PLARGE_INTEGER Timeout OPTIONAL,
|
|
|
|
OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
|
2003-02-27 15:38:36 +00:00
|
|
|
{
|
2006-01-05 04:26:55 +00:00
|
|
|
PKMUTANT CurrentObject;
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
PKWAIT_BLOCK WaitBlock;
|
2006-09-16 00:07:02 +00:00
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
2007-01-23 18:39:47 +00:00
|
|
|
PKWAIT_BLOCK TimerBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
|
|
|
|
PKTIMER Timer = &Thread->Timer;
|
2006-01-06 11:58:17 +00:00
|
|
|
NTSTATUS WaitStatus = STATUS_SUCCESS;
|
2006-07-14 01:03:27 +00:00
|
|
|
BOOLEAN Swappable;
|
2006-07-22 17:19:09 +00:00
|
|
|
PLARGE_INTEGER OriginalDueTime = Timeout;
|
2011-06-12 21:15:33 +00:00
|
|
|
LARGE_INTEGER DueTime = {{0}}, NewDueTime, InterruptTime;
|
2007-01-24 06:50:28 +00:00
|
|
|
ULONG Index, Hand = 0;
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
|
2012-06-19 10:43:38 +00:00
|
|
|
if (Thread->WaitNext)
|
2019-05-30 13:44:56 +00:00
|
|
|
ASSERT(KeGetCurrentIrql() == SYNCH_LEVEL);
|
2021-05-21 07:41:27 +00:00
|
|
|
else if (!Timeout || (Timeout->QuadPart != 0))
|
2012-06-19 10:43:38 +00:00
|
|
|
{
|
2021-05-21 07:41:27 +00:00
|
|
|
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
|
2012-06-19 10:43:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
|
2012-06-19 08:24:32 +00:00
|
|
|
|
2006-07-13 21:48:45 +00:00
|
|
|
/* Make sure the Wait Count is valid */
|
2006-01-05 04:26:55 +00:00
|
|
|
if (!WaitBlockArray)
|
|
|
|
{
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
/* Check in regards to the Thread Object Limit */
|
2006-07-13 21:48:45 +00:00
|
|
|
if (Count > THREAD_WAIT_OBJECTS)
|
|
|
|
{
|
|
|
|
/* Bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(MAXIMUM_WAIT_OBJECTS_EXCEEDED);
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
/* Use the Thread's Wait Block */
|
2006-09-16 00:07:02 +00:00
|
|
|
WaitBlockArray = &Thread->WaitBlock[0];
|
2006-01-05 04:26:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-13 21:48:45 +00:00
|
|
|
/* Using our own Block Array, so check with the System Object Limit */
|
|
|
|
if (Count > MAXIMUM_WAIT_OBJECTS)
|
|
|
|
{
|
|
|
|
/* Bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(MAXIMUM_WAIT_OBJECTS_EXCEEDED);
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
2005-02-28 17:40:15 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-16 00:07:02 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(Count != 0);
|
|
|
|
|
|
|
|
/* Check if the lock is already held */
|
2007-01-23 18:39:47 +00:00
|
|
|
if (!Thread->WaitNext) goto WaitStart;
|
2006-01-06 08:00:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Otherwise, we already have the lock, so initialize the wait */
|
|
|
|
Thread->WaitNext = FALSE;
|
2007-10-20 05:48:25 +00:00
|
|
|
/* Note that KxMultiThreadWait is a macro, defined in ke_x.h, that */
|
|
|
|
/* uses (and modifies some of) the following local */
|
|
|
|
/* variables: */
|
|
|
|
/* Thread, Index, WaitBlock, Timer, Timeout, Hand and Swappable. */
|
|
|
|
/* If it looks like this code doesn't actually wait for any objects */
|
|
|
|
/* at all, it's because the setup is done by that macro. */
|
2007-01-23 18:39:47 +00:00
|
|
|
KxMultiThreadWait();
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Start wait loop */
|
|
|
|
for (;;)
|
2006-09-16 00:07:02 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Disable pre-emption */
|
|
|
|
Thread->Preempted = FALSE;
|
2006-07-13 21:48:45 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if a kernel APC is pending and we're below APC_LEVEL */
|
|
|
|
if ((Thread->ApcState.KernelApcPending) && !(Thread->SpecialApcDisable) &&
|
|
|
|
(Thread->WaitIrql < APC_LEVEL))
|
2006-09-16 00:07:02 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Unlock the dispatcher */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check what kind of wait this is */
|
|
|
|
Index = 0;
|
|
|
|
if (WaitType == WaitAny)
|
2006-09-16 00:07:02 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Loop blocks */
|
|
|
|
do
|
2006-01-05 04:26:55 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Get the Current Object */
|
|
|
|
CurrentObject = (PKMUTANT)Object[Index];
|
|
|
|
ASSERT(CurrentObject->Header.Type != QueueObject);
|
|
|
|
|
|
|
|
/* Check if the Object is a mutant */
|
|
|
|
if (CurrentObject->Header.Type == MutantObject)
|
2006-01-05 04:26:55 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if it's signaled */
|
|
|
|
if ((CurrentObject->Header.SignalState > 0) ||
|
|
|
|
(Thread == CurrentObject->OwnerThread))
|
|
|
|
{
|
|
|
|
/* This is a Wait Any, so unwait this and exit */
|
|
|
|
if (CurrentObject->Header.SignalState !=
|
|
|
|
(LONG)MINLONG)
|
|
|
|
{
|
|
|
|
/* Normal signal state, unwait it and return */
|
|
|
|
KiSatisfyMutantWait(CurrentObject, Thread);
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
WaitStatus = (NTSTATUS)Thread->WaitStatus | Index;
|
2007-01-23 18:39:47 +00:00
|
|
|
goto DontWait;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Raise an exception (see wasm.ru) */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
ExRaiseStatus(STATUS_MUTANT_LIMIT_EXCEEDED);
|
|
|
|
}
|
|
|
|
}
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
2007-01-23 18:39:47 +00:00
|
|
|
else if (CurrentObject->Header.SignalState > 0)
|
2006-01-05 04:26:55 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Another signaled object, unwait and return */
|
2007-01-23 22:46:38 +00:00
|
|
|
KiSatisfyNonMutantWait(CurrentObject);
|
2007-01-23 18:39:47 +00:00
|
|
|
WaitStatus = Index;
|
|
|
|
goto DontWait;
|
2006-01-05 04:26:55 +00:00
|
|
|
}
|
2007-01-23 18:39:47 +00:00
|
|
|
|
|
|
|
/* Go to the next block */
|
|
|
|
Index++;
|
|
|
|
} while (Index < Count);
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
}
|
2007-01-23 18:39:47 +00:00
|
|
|
else
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Loop blocks */
|
|
|
|
do
|
2006-07-13 21:48:45 +00:00
|
|
|
{
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Get the Current Object */
|
|
|
|
CurrentObject = (PKMUTANT)Object[Index];
|
|
|
|
ASSERT(CurrentObject->Header.Type != QueueObject);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we're dealing with a mutant again */
|
|
|
|
if (CurrentObject->Header.Type == MutantObject)
|
|
|
|
{
|
|
|
|
/* Check if it has an invalid count */
|
|
|
|
if ((Thread == CurrentObject->OwnerThread) &&
|
2008-12-03 17:28:59 +00:00
|
|
|
(CurrentObject->Header.SignalState == (LONG)MINLONG))
|
2007-01-23 18:39:47 +00:00
|
|
|
{
|
|
|
|
/* Raise an exception */
|
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
|
|
|
ExRaiseStatus(STATUS_MUTANT_LIMIT_EXCEEDED);
|
|
|
|
}
|
|
|
|
else if ((CurrentObject->Header.SignalState <= 0) &&
|
|
|
|
(Thread != CurrentObject->OwnerThread))
|
|
|
|
{
|
|
|
|
/* We don't own it, can't satisfy the wait */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CurrentObject->Header.SignalState <= 0)
|
|
|
|
{
|
|
|
|
/* Not signaled, can't satisfy */
|
|
|
|
break;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Go to the next block */
|
|
|
|
Index++;
|
|
|
|
} while (Index < Count);
|
1998-10-05 04:01:30 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we've went through all the objects */
|
|
|
|
if (Index == Count)
|
|
|
|
{
|
|
|
|
/* Loop wait blocks */
|
|
|
|
WaitBlock = WaitBlockArray;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get the object and satisfy it */
|
|
|
|
CurrentObject = (PKMUTANT)WaitBlock->Object;
|
|
|
|
KiSatisfyObjectWait(CurrentObject, Thread);
|
2006-07-13 21:48:45 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Go to the next block */
|
|
|
|
WaitBlock = WaitBlock->NextWaitBlock;
|
|
|
|
} while(WaitBlock != WaitBlockArray);
|
2006-07-13 21:48:45 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Set the wait status and get out */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
WaitStatus = (NTSTATUS)Thread->WaitStatus;
|
2007-01-23 18:39:47 +00:00
|
|
|
goto DontWait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we can satisfy the Alertable request */
|
|
|
|
WaitStatus = KiCheckAlertability(Thread, Alertable, WaitMode);
|
|
|
|
if (WaitStatus != STATUS_WAIT_0) break;
|
2006-07-22 17:19:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Enable the Timeout Timer if there was any specified */
|
|
|
|
if (Timeout)
|
|
|
|
{
|
|
|
|
/* Check if the timer expired */
|
|
|
|
InterruptTime.QuadPart = KeQueryInterruptTime();
|
2007-01-23 22:46:38 +00:00
|
|
|
if ((ULONGLONG)InterruptTime.QuadPart >=
|
|
|
|
Timer->DueTime.QuadPart)
|
2007-01-23 18:39:47 +00:00
|
|
|
{
|
|
|
|
/* It did, so we don't need to wait */
|
|
|
|
WaitStatus = STATUS_TIMEOUT;
|
|
|
|
goto DontWait;
|
|
|
|
}
|
2005-02-28 17:40:15 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* It didn't, so activate it */
|
|
|
|
Timer->Header.Inserted = TRUE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Link the wait blocks */
|
|
|
|
WaitBlock->NextWaitBlock = TimerBlock;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Insert into Object's Wait List*/
|
|
|
|
WaitBlock = WaitBlockArray;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get the Current Object */
|
|
|
|
CurrentObject = WaitBlock->Object;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Link the Object to this Wait Block */
|
|
|
|
InsertTailList(&CurrentObject->Header.WaitListHead,
|
|
|
|
&WaitBlock->WaitListEntry);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Move to the next Wait Block */
|
|
|
|
WaitBlock = WaitBlock->NextWaitBlock;
|
|
|
|
} while (WaitBlock != WaitBlockArray);
|
2006-01-06 08:00:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Handle Kernel Queues */
|
|
|
|
if (Thread->Queue) KiActivateWaiterQueue(Thread->Queue);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Setup the wait information */
|
|
|
|
Thread->State = Waiting;
|
|
|
|
|
|
|
|
/* Add the thread to the wait list */
|
|
|
|
KiAddThreadToWaitList(Thread, Swappable);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Activate thread swap */
|
|
|
|
ASSERT(Thread->WaitIrql <= DISPATCH_LEVEL);
|
|
|
|
KiSetThreadSwapBusy(Thread);
|
2006-09-16 00:07:02 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we have a timer */
|
|
|
|
if (Timeout)
|
|
|
|
{
|
|
|
|
/* Insert it */
|
2007-01-24 06:50:28 +00:00
|
|
|
KxInsertTimer(Timer, Hand);
|
2007-01-23 18:39:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, unlock the dispatcher */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2007-01-23 18:39:47 +00:00
|
|
|
}
|
2006-09-16 00:07:02 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Swap the thread */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
WaitStatus = (NTSTATUS)KiSwapThread(Thread, KeGetCurrentPrcb());
|
2006-09-16 00:07:02 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we were executing an APC */
|
|
|
|
if (WaitStatus != STATUS_KERNEL_APC) return WaitStatus;
|
2006-01-06 08:00:09 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
/* Check if we had a timeout */
|
|
|
|
if (Timeout)
|
|
|
|
{
|
|
|
|
/* Recalculate due times */
|
|
|
|
Timeout = KiRecalculateDueTime(OriginalDueTime,
|
|
|
|
&DueTime,
|
|
|
|
&NewDueTime);
|
|
|
|
}
|
2006-07-13 21:48:45 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-23 18:39:47 +00:00
|
|
|
WaitStart:
|
|
|
|
/* Setup a new wait */
|
|
|
|
Thread->WaitIrql = KeRaiseIrqlToSynchLevel();
|
|
|
|
KxMultiThreadWait();
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2006-09-16 00:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We are done */
|
2007-01-23 18:39:47 +00:00
|
|
|
KiReleaseDispatcherLock(Thread->WaitIrql);
|
2006-01-06 08:37:46 +00:00
|
|
|
return WaitStatus;
|
2005-07-30 23:43:45 +00:00
|
|
|
|
|
|
|
DontWait:
|
2007-01-17 20:44:37 +00:00
|
|
|
/* Release dispatcher lock but maintain high IRQL */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2005-07-30 23:43:45 +00:00
|
|
|
|
2007-01-17 20:44:37 +00:00
|
|
|
/* Adjust the Quantum and return the wait status */
|
|
|
|
KiAdjustQuantumThread(Thread);
|
2006-01-06 08:37:46 +00:00
|
|
|
return WaitStatus;
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
}
|
2005-02-28 17:40:15 +00:00
|
|
|
|
2006-09-10 15:23:20 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtDelayExecution(IN BOOLEAN Alertable,
|
|
|
|
IN PLARGE_INTEGER DelayInterval)
|
|
|
|
{
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
LARGE_INTEGER SafeInterval;
|
2009-08-24 19:58:15 +00:00
|
|
|
NTSTATUS Status;
|
2006-09-10 15:23:20 +00:00
|
|
|
|
2006-09-14 15:48:02 +00:00
|
|
|
/* Check the previous mode */
|
2009-08-24 19:58:15 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
2006-09-10 15:23:20 +00:00
|
|
|
{
|
2006-09-14 15:48:02 +00:00
|
|
|
/* Enter SEH for probing */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2006-09-10 15:23:20 +00:00
|
|
|
{
|
2006-09-14 15:48:02 +00:00
|
|
|
/* Probe and capture the time out */
|
2006-09-10 15:23:20 +00:00
|
|
|
SafeInterval = ProbeForReadLargeInteger(DelayInterval);
|
|
|
|
DelayInterval = &SafeInterval;
|
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-09-10 15:23:20 +00:00
|
|
|
{
|
2009-08-24 19:58:15 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-09-10 15:23:20 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2006-09-10 15:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the Kernel Function */
|
|
|
|
Status = KeDelayExecutionThread(PreviousMode,
|
|
|
|
Alertable,
|
|
|
|
DelayInterval);
|
|
|
|
|
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
Dispatching & Queue Rewrite II:
- Rewrote wait code. It is now cleaner, more optimized and faster. All waiting
functions are now clearly differentiated instead of sharing code. These functions
are called up to a dozen times a second, so having dedicated code for each of
them is a real boost in speed.
- Fixed several queue issues, made a dedicated queue wait/wake function (you are not
supposed to use KeWaitFor on a queue, and this is also a speed boost), and make it
compatible with new wait code.
- Optimized Work Queue code to be much smaller and better organized, by using an
array instead of hard-coded multiple static variables. Also, add support for the
real NT structures and implementation, paving the road for Dynamic Work Items, which
also have timeouts, and deadlock dection + debug info.
- Simplified PsBlockThread and made it compatible with wait code.
- Added support for priority boosting when unwaiting a thread; will use later, as well
as put proper boosting for dispatch objects.
- Inlined all dispatcher lock functions and header initialization for speed.
- Moved executive wait code into ob.
svn path=/trunk/; revision=14047
2005-03-14 05:54:32 +00:00
|
|
|
/* EOF */
|