2006-01-03 23:36:05 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* FILE: ntoskrnl/ex/pushlock.c
|
|
|
|
* PURPOSE: Pushlock and Cache-Aware Pushlock Implementation
|
|
|
|
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
2007-03-02 07:23:19 +00:00
|
|
|
#include <debug.h>
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* DATA **********************************************************************/
|
|
|
|
|
2009-02-06 14:47:19 +00:00
|
|
|
ULONG ExPushLockSpinCount = 0;
|
|
|
|
|
2007-03-02 07:23:19 +00:00
|
|
|
#undef EX_PUSH_LOCK
|
|
|
|
#undef PEX_PUSH_LOCK
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
2010-01-13 22:35:43 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
#define InterlockedAndPointer(ptr,val) InterlockedAnd64((PLONGLONG)ptr,(LONGLONG)val)
|
|
|
|
#else
|
|
|
|
#define InterlockedAndPointer(ptr,val) InterlockedAnd((PLONG)ptr,(LONG)val)
|
|
|
|
#endif
|
|
|
|
|
2006-01-03 23:36:05 +00:00
|
|
|
/*++
|
|
|
|
* @name ExpInitializePushLocks
|
|
|
|
*
|
|
|
|
* The ExpInitializePushLocks routine initialized Pushlock support.
|
|
|
|
*
|
|
|
|
* @param None.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks The ExpInitializePushLocks routine sets up the spin on SMP machines.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2010-11-02 16:29:06 +00:00
|
|
|
INIT_FUNCTION
|
2006-01-03 23:36:05 +00:00
|
|
|
ExpInitializePushLocks(VOID)
|
|
|
|
{
|
2009-02-06 14:47:19 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2006-01-03 23:36:05 +00:00
|
|
|
/* Initialize an internal 1024-iteration spin for MP CPUs */
|
2009-02-06 14:47:19 +00:00
|
|
|
if (KeNumberProcessors > 1)
|
|
|
|
ExPushLockSpinCount = 1024;
|
|
|
|
#endif
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExfWakePushLock
|
|
|
|
*
|
|
|
|
* The ExfWakePushLock routine wakes a Pushlock that is in the waiting
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a pushlock that is waiting.
|
|
|
|
*
|
|
|
|
* @param OldValue
|
|
|
|
* Last known value of the pushlock before this routine was called.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks This is an internal routine; do not call it manually. Only the system
|
|
|
|
* can properly know if the pushlock is ready to be awakened or not.
|
|
|
|
* External callers should use ExfTrytoWakePushLock.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfWakePushLock(PEX_PUSH_LOCK PushLock,
|
|
|
|
EX_PUSH_LOCK OldValue)
|
|
|
|
{
|
|
|
|
EX_PUSH_LOCK NewValue;
|
2008-04-01 18:14:01 +00:00
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK PreviousWaitBlock, FirstWaitBlock, LastWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock;
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Start main wake loop */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(!OldValue.MultipleShared);
|
|
|
|
|
|
|
|
/* Check if it's locked */
|
2007-04-11 20:00:53 +00:00
|
|
|
while (OldValue.Locked)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2007-04-11 20:00:53 +00:00
|
|
|
/* It's not waking anymore */
|
|
|
|
NewValue.Value = OldValue.Value &~ EX_PUSH_LOCK_WAKING;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(!NewValue.Waking);
|
|
|
|
ASSERT(NewValue.Locked);
|
|
|
|
ASSERT(NewValue.Waiting);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Write the New Value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2007-04-11 20:00:53 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value == OldValue.Value) return;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Someone changed the value behind our back, update it*/
|
|
|
|
OldValue = NewValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the First Block */
|
2010-01-13 22:35:43 +00:00
|
|
|
FirstWaitBlock = (PEX_PUSH_LOCK_WAIT_BLOCK)(OldValue.Value &
|
2006-01-03 23:36:05 +00:00
|
|
|
~EX_PUSH_LOCK_PTR_BITS);
|
2008-04-01 18:14:01 +00:00
|
|
|
WaitBlock = FirstWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Try to find the last block */
|
|
|
|
while (TRUE)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Get the last wait block */
|
|
|
|
LastWaitBlock = WaitBlock->Last;
|
[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
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Check if we found it */
|
|
|
|
if (LastWaitBlock)
|
|
|
|
{
|
|
|
|
/* Use it */
|
|
|
|
WaitBlock = LastWaitBlock;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:36:05 +00:00
|
|
|
/* Save the previous block */
|
2008-04-01 18:14:01 +00:00
|
|
|
PreviousWaitBlock = WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Move to next block */
|
2008-04-01 18:14:01 +00:00
|
|
|
WaitBlock = WaitBlock->Next;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Save the previous block */
|
2008-04-01 18:14:01 +00:00
|
|
|
WaitBlock->Previous = PreviousWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the last Wait Block is not Exclusive or if it's the only one */
|
|
|
|
PreviousWaitBlock = WaitBlock->Previous;
|
|
|
|
if (!(WaitBlock->Flags & EX_PUSH_LOCK_FLAGS_EXCLUSIVE) ||
|
|
|
|
!(PreviousWaitBlock))
|
|
|
|
{
|
|
|
|
/* Destroy the pushlock */
|
2007-04-11 20:00:53 +00:00
|
|
|
NewValue.Value = 0;
|
|
|
|
ASSERT(!NewValue.Waking);
|
|
|
|
|
|
|
|
/* Write the New Value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2007-04-11 20:00:53 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value == OldValue.Value) break;
|
|
|
|
|
|
|
|
/* Someone changed the value behind our back, update it*/
|
|
|
|
OldValue = NewValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Link the wait blocks */
|
|
|
|
FirstWaitBlock->Last = PreviousWaitBlock;
|
|
|
|
WaitBlock->Previous = NULL;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(FirstWaitBlock != WaitBlock);
|
|
|
|
ASSERT(PushLock->Waiting);
|
|
|
|
|
|
|
|
/* Remove waking bit from pushlock */
|
2010-01-13 22:35:43 +00:00
|
|
|
InterlockedAndPointer(&PushLock->Value, ~EX_PUSH_LOCK_WAKING);
|
2008-06-26 08:26:48 +00:00
|
|
|
|
|
|
|
/* Leave the loop */
|
|
|
|
break;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if there's a previous block */
|
|
|
|
OldIrql = DISPATCH_LEVEL;
|
|
|
|
if (WaitBlock->Previous)
|
|
|
|
{
|
|
|
|
/* Raise to Dispatch */
|
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Signaling loop */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Get the previous Wait block */
|
|
|
|
PreviousWaitBlock = WaitBlock->Previous;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(!WaitBlock->Signaled);
|
|
|
|
|
2009-06-17 12:44:05 +00:00
|
|
|
#if DBG
|
2006-01-03 23:36:05 +00:00
|
|
|
/* We are about to get signaled */
|
|
|
|
WaitBlock->Signaled = TRUE;
|
2006-01-05 00:56:44 +00:00
|
|
|
#endif
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Set the Wait Bit in the Wait Block */
|
|
|
|
if (!InterlockedBitTestAndReset(&WaitBlock->Flags, 1))
|
|
|
|
{
|
|
|
|
/* Nobody signaled us, so do it */
|
|
|
|
KeSignalGateBoostPriority(&WaitBlock->WakeGate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the wait block and check if there still is one to loop*/
|
|
|
|
WaitBlock = PreviousWaitBlock;
|
|
|
|
if (!WaitBlock) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have to lower back the IRQL */
|
|
|
|
if (OldIrql != DISPATCH_LEVEL) KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExpOptimizePushLockList
|
|
|
|
*
|
|
|
|
* The ExpOptimizePushLockList routine optimizes the list of waiters
|
|
|
|
* associated to a pushlock's wait block.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a pushlock whose waiter list needs to be optimized.
|
|
|
|
*
|
|
|
|
* @param OldValue
|
|
|
|
* Last known value of the pushlock before this routine was called.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks At the end of the optimization, the pushlock will also be wakened.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExpOptimizePushLockList(PEX_PUSH_LOCK PushLock,
|
|
|
|
EX_PUSH_LOCK OldValue)
|
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock, LastWaitBlock, PreviousWaitBlock, FirstWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
EX_PUSH_LOCK NewValue;
|
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Start main loop */
|
|
|
|
for (;;)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Check if we've been unlocked */
|
|
|
|
if (!OldValue.Locked)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Wake us up and leave */
|
|
|
|
ExfWakePushLock(PushLock, OldValue);
|
|
|
|
break;
|
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Get the wait block */
|
2010-01-13 22:35:43 +00:00
|
|
|
WaitBlock = (PEX_PUSH_LOCK_WAIT_BLOCK)(OldValue.Value &
|
2008-04-01 18:14:01 +00:00
|
|
|
~EX_PUSH_LOCK_PTR_BITS);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Loop the blocks */
|
|
|
|
FirstWaitBlock = WaitBlock;
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Get the last wait block */
|
2006-01-03 23:36:05 +00:00
|
|
|
LastWaitBlock = WaitBlock->Last;
|
2008-04-01 18:14:01 +00:00
|
|
|
if (LastWaitBlock)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Set this as the new last block, we're done */
|
|
|
|
FirstWaitBlock->Last = LastWaitBlock;
|
|
|
|
break;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Save the block */
|
|
|
|
PreviousWaitBlock = WaitBlock;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Get the next block */
|
|
|
|
WaitBlock = WaitBlock->Next;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Save the previous */
|
|
|
|
WaitBlock->Previous = PreviousWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Remove the wake bit */
|
|
|
|
NewValue.Value = OldValue.Value &~ EX_PUSH_LOCK_WAKING;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(NewValue.Locked);
|
|
|
|
ASSERT(!NewValue.Waking);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Update the value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2008-04-01 18:14:01 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* If we updated correctly, leave */
|
|
|
|
if (NewValue.Value == OldValue.Value) break;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Update value */
|
|
|
|
OldValue = NewValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExTimedWaitForUnblockPushLock
|
|
|
|
*
|
|
|
|
* The ExTimedWaitForUnblockPushLock routine waits for a pushlock
|
|
|
|
* to be unblocked, for a specified internal.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a pushlock whose waiter list needs to be optimized.
|
|
|
|
*
|
|
|
|
* @param WaitBlock
|
|
|
|
* Pointer to the pushlock's wait block.
|
|
|
|
*
|
|
|
|
* @param Timeout
|
|
|
|
* Amount of time to wait for this pushlock to be unblocked.
|
|
|
|
*
|
|
|
|
* @return STATUS_SUCCESS is the pushlock is now unblocked, otherwise the error
|
|
|
|
* code returned by KeWaitForSingleObject.
|
|
|
|
*
|
|
|
|
* @remarks If the wait fails, then a manual unblock is attempted.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
NTSTATUS
|
|
|
|
FASTCALL
|
|
|
|
ExTimedWaitForUnblockPushLock(IN PEX_PUSH_LOCK PushLock,
|
|
|
|
IN PVOID WaitBlock,
|
|
|
|
IN PLARGE_INTEGER Timeout)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Initialize the wait event */
|
|
|
|
KeInitializeEvent(&((PEX_PUSH_LOCK_WAIT_BLOCK)WaitBlock)->WakeEvent,
|
2008-04-01 18:14:01 +00:00
|
|
|
SynchronizationEvent,
|
2006-01-03 23:36:05 +00:00
|
|
|
FALSE);
|
|
|
|
|
2009-02-06 14:47:19 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2006-01-03 23:36:05 +00:00
|
|
|
/* Spin on the push lock if necessary */
|
2009-02-06 14:47:19 +00:00
|
|
|
if (ExPushLockSpinCount)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2009-02-06 14:47:19 +00:00
|
|
|
ULONG i = ExPushLockSpinCount;
|
|
|
|
|
|
|
|
do
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Check if we got lucky and can leave early */
|
2009-02-06 14:47:19 +00:00
|
|
|
if (!(*(volatile LONG *)&((PEX_PUSH_LOCK_WAIT_BLOCK)WaitBlock)->Flags & EX_PUSH_LOCK_WAITING))
|
2006-01-03 23:36:05 +00:00
|
|
|
return STATUS_SUCCESS;
|
2009-02-06 14:47:19 +00:00
|
|
|
|
2006-01-03 23:36:05 +00:00
|
|
|
YieldProcessor();
|
2009-02-06 14:47:19 +00:00
|
|
|
} while (--i);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
2009-02-06 14:47:19 +00:00
|
|
|
#endif
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Now try to remove the wait bit */
|
|
|
|
if (InterlockedBitTestAndReset(&((PEX_PUSH_LOCK_WAIT_BLOCK)WaitBlock)->Flags,
|
2008-04-01 18:14:01 +00:00
|
|
|
EX_PUSH_LOCK_FLAGS_WAIT_V))
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Nobody removed it already, let's do a full wait */
|
|
|
|
Status = KeWaitForSingleObject(&((PEX_PUSH_LOCK_WAIT_BLOCK)WaitBlock)->
|
|
|
|
WakeEvent,
|
|
|
|
WrPushLock,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
Timeout);
|
2008-06-18 11:34:10 +00:00
|
|
|
/* Check if the wait was satisfied */
|
|
|
|
if (Status != STATUS_SUCCESS)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-06-18 11:34:10 +00:00
|
|
|
/* Try unblocking the pushlock if it was not */
|
2006-01-03 23:36:05 +00:00
|
|
|
ExfUnblockPushLock(PushLock, WaitBlock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Someone beat us to it, no need to wait */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2007-01-22 06:47:44 +00:00
|
|
|
/*++
|
|
|
|
* @name ExWaitForUnblockPushLock
|
|
|
|
*
|
|
|
|
* The ExWaitForUnblockPushLock routine waits for a pushlock
|
|
|
|
* to be unblocked, for a specified internal.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a pushlock whose waiter list needs to be optimized.
|
|
|
|
*
|
|
|
|
* @param WaitBlock
|
|
|
|
* Pointer to the pushlock's wait block.
|
|
|
|
*
|
|
|
|
* @return STATUS_SUCCESS is the pushlock is now unblocked, otherwise the error
|
|
|
|
* code returned by KeWaitForSingleObject.
|
|
|
|
*
|
|
|
|
* @remarks If the wait fails, then a manual unblock is attempted.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExWaitForUnblockPushLock(IN PEX_PUSH_LOCK PushLock,
|
2007-01-22 22:16:13 +00:00
|
|
|
IN PVOID WaitBlock)
|
2007-01-22 06:47:44 +00:00
|
|
|
{
|
|
|
|
/* Call the timed function with no timeout */
|
|
|
|
ExTimedWaitForUnblockPushLock(PushLock, WaitBlock, NULL);
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:36:05 +00:00
|
|
|
/*++
|
|
|
|
* @name ExBlockPushLock
|
|
|
|
*
|
|
|
|
* The ExBlockPushLock routine blocks a pushlock.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a pushlock whose waiter list needs to be optimized.
|
|
|
|
*
|
|
|
|
* @param WaitBlock
|
|
|
|
* Pointer to the pushlock's wait block.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExBlockPushLock(PEX_PUSH_LOCK PushLock,
|
2007-01-22 06:47:44 +00:00
|
|
|
PVOID pWaitBlock)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2007-01-22 06:47:44 +00:00
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock = pWaitBlock;
|
|
|
|
EX_PUSH_LOCK NewValue, OldValue;
|
2007-04-11 20:00:53 +00:00
|
|
|
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Detect invalid wait block alignment */
|
2007-04-11 20:00:53 +00:00
|
|
|
ASSERT(((ULONG_PTR)pWaitBlock & 0xF) == 0);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Set the waiting bit */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Flags = EX_PUSH_LOCK_FLAGS_WAIT;
|
2007-04-11 20:00:53 +00:00
|
|
|
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Get the old value */
|
|
|
|
OldValue = *PushLock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Start block loop */
|
2006-01-03 23:36:05 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Link the wait blocks */
|
|
|
|
WaitBlock->Next = OldValue.Ptr;
|
|
|
|
|
2006-01-03 23:36:05 +00:00
|
|
|
/* Set the new wait block value */
|
2007-01-22 06:47:44 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
|
|
|
WaitBlock,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (OldValue.Ptr == NewValue.Ptr) break;
|
2007-04-11 20:00:53 +00:00
|
|
|
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Try again with the new value */
|
2008-06-18 11:34:10 +00:00
|
|
|
OldValue = NewValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExAcquirePushLockExclusive
|
|
|
|
* @implemented NT5.1
|
|
|
|
*
|
|
|
|
* The ExAcquirePushLockExclusive macro exclusively acquires a PushLock.
|
|
|
|
*
|
|
|
|
* @params PushLock
|
|
|
|
* Pointer to the pushlock which is to be acquired.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks Callers of ExAcquirePushLockShared must be running at IRQL <= APC_LEVEL.
|
|
|
|
* This macro should usually be paired up with KeAcquireCriticalRegion.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
|
|
|
|
{
|
|
|
|
EX_PUSH_LOCK OldValue = *PushLock, NewValue, TempValue;
|
|
|
|
BOOLEAN NeedWake;
|
2007-03-02 07:23:19 +00:00
|
|
|
DEFINE_WAIT_BLOCK(WaitBlock);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Start main loop */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Check if it's unlocked */
|
|
|
|
if (!OldValue.Locked)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
|
|
|
NewValue.Value = OldValue.Value | EX_PUSH_LOCK_LOCK;
|
|
|
|
ASSERT(NewValue.Locked);
|
|
|
|
|
|
|
|
/* Set the new value */
|
2010-01-13 22:35:43 +00:00
|
|
|
if (InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr) != OldValue.Ptr)
|
|
|
|
{
|
|
|
|
/* Retry */
|
|
|
|
OldValue = *PushLock;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Break out of the loop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We'll have to create a Waitblock */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Flags = EX_PUSH_LOCK_FLAGS_EXCLUSIVE |
|
|
|
|
EX_PUSH_LOCK_FLAGS_WAIT;
|
|
|
|
WaitBlock->Previous = NULL;
|
2006-01-03 23:36:05 +00:00
|
|
|
NeedWake = FALSE;
|
|
|
|
|
|
|
|
/* Check if there is already a waiter */
|
|
|
|
if (OldValue.Waiting)
|
|
|
|
{
|
|
|
|
/* Nobody is the last waiter yet */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Last = NULL;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* We are an exclusive waiter */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->ShareCount = 0;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Set the current Wait Block pointer */
|
2010-01-13 22:35:43 +00:00
|
|
|
WaitBlock->Next = (PEX_PUSH_LOCK_WAIT_BLOCK)(
|
|
|
|
OldValue.Value &~ EX_PUSH_LOCK_PTR_BITS);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Point to ours */
|
|
|
|
NewValue.Value = (OldValue.Value & EX_PUSH_LOCK_MULTIPLE_SHARED) |
|
2007-04-11 20:00:53 +00:00
|
|
|
EX_PUSH_LOCK_LOCK |
|
|
|
|
EX_PUSH_LOCK_WAKING |
|
|
|
|
EX_PUSH_LOCK_WAITING |
|
2012-04-03 13:27:45 +00:00
|
|
|
(ULONG_PTR)WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Check if the pushlock was already waking */
|
2008-06-18 09:53:38 +00:00
|
|
|
if (!OldValue.Waking) NeedWake = TRUE;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We are the first waiter, so loop the wait block */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Last = WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Set the share count */
|
[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
|
|
|
WaitBlock->ShareCount = (LONG)OldValue.Shared;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Check if someone is sharing this pushlock */
|
|
|
|
if (OldValue.Shared > 1)
|
|
|
|
{
|
|
|
|
/* Point to our wait block */
|
|
|
|
NewValue.Value = EX_PUSH_LOCK_MULTIPLE_SHARED |
|
|
|
|
EX_PUSH_LOCK_LOCK |
|
|
|
|
EX_PUSH_LOCK_WAITING |
|
2012-04-03 13:27:45 +00:00
|
|
|
(ULONG_PTR)WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No shared count */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->ShareCount = 0;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Point to our wait block */
|
|
|
|
NewValue.Value = EX_PUSH_LOCK_LOCK |
|
|
|
|
EX_PUSH_LOCK_WAITING |
|
2012-04-03 13:27:45 +00:00
|
|
|
(ULONG_PTR)WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DBG
|
|
|
|
/* Setup the Debug Wait Block */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Signaled = 0;
|
|
|
|
WaitBlock->OldValue = OldValue;
|
|
|
|
WaitBlock->NewValue = NewValue;
|
|
|
|
WaitBlock->PushLock = PushLock;
|
2006-01-03 23:36:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waiting);
|
|
|
|
ASSERT(NewValue.Locked);
|
|
|
|
|
|
|
|
/* Write the new value */
|
|
|
|
TempValue = NewValue;
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value != OldValue.Value)
|
|
|
|
{
|
|
|
|
/* Retry */
|
|
|
|
OldValue = *PushLock;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the pushlock needed waking */
|
|
|
|
if (NeedWake)
|
|
|
|
{
|
|
|
|
/* Scan the Waiters and Wake PushLocks */
|
|
|
|
ExpOptimizePushLockList(PushLock, TempValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the Wait Gate */
|
2007-01-22 06:47:44 +00:00
|
|
|
KeInitializeGate(&WaitBlock->WakeGate);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2009-02-06 14:47:19 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2006-01-03 23:36:05 +00:00
|
|
|
/* Now spin on the push lock if necessary */
|
2009-02-06 14:47:19 +00:00
|
|
|
if (ExPushLockSpinCount)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2009-02-06 14:47:19 +00:00
|
|
|
ULONG i = ExPushLockSpinCount;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(*(volatile LONG *)&WaitBlock->Flags & EX_PUSH_LOCK_WAITING))
|
|
|
|
break;
|
|
|
|
|
|
|
|
YieldProcessor();
|
|
|
|
} while (--i);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
2009-02-06 14:47:19 +00:00
|
|
|
#endif
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Now try to remove the wait bit */
|
2007-01-22 06:47:44 +00:00
|
|
|
if (InterlockedBitTestAndReset(&WaitBlock->Flags, 1))
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Nobody removed it already, let's do a full wait */
|
2007-01-22 06:47:44 +00:00
|
|
|
KeWaitForGate(&WaitBlock->WakeGate, WrPushLock, KernelMode);
|
|
|
|
ASSERT(WaitBlock->Signaled);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We shouldn't be shared anymore */
|
2007-01-22 06:47:44 +00:00
|
|
|
ASSERT((WaitBlock->ShareCount == 0));
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Loop again */
|
|
|
|
OldValue = NewValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
2007-04-11 20:00:53 +00:00
|
|
|
* @name ExAcquirePushLockShared
|
2006-01-03 23:36:05 +00:00
|
|
|
* @implemented NT5.1
|
|
|
|
*
|
2007-04-11 20:00:53 +00:00
|
|
|
* The ExAcquirePushLockShared routine acquires a shared PushLock.
|
2006-01-03 23:36:05 +00:00
|
|
|
*
|
|
|
|
* @params PushLock
|
|
|
|
* Pointer to the pushlock which is to be acquired.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks Callers of ExAcquirePushLockShared must be running at IRQL <= APC_LEVEL.
|
|
|
|
* This macro should usually be paired up with KeAcquireCriticalRegion.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfAcquirePushLockShared(PEX_PUSH_LOCK PushLock)
|
|
|
|
{
|
|
|
|
EX_PUSH_LOCK OldValue = *PushLock, NewValue;
|
|
|
|
BOOLEAN NeedWake;
|
2007-03-02 07:23:19 +00:00
|
|
|
DEFINE_WAIT_BLOCK(WaitBlock);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Start main loop */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Check if it's unlocked or if it's waiting without any sharers */
|
2007-04-11 20:00:53 +00:00
|
|
|
if (!(OldValue.Locked) || (!(OldValue.Waiting) && (OldValue.Shared > 0)))
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Check if anyone is waiting on it */
|
|
|
|
if (!OldValue.Waiting)
|
|
|
|
{
|
|
|
|
/* Increase the share count and lock it */
|
|
|
|
NewValue.Value = OldValue.Value | EX_PUSH_LOCK_LOCK;
|
|
|
|
NewValue.Shared++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Simply set the lock bit */
|
|
|
|
NewValue.Value = OldValue.Value | EX_PUSH_LOCK_LOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Locked);
|
|
|
|
|
|
|
|
/* Set the new value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value != OldValue.Value)
|
|
|
|
{
|
|
|
|
/* Retry */
|
2008-06-18 11:34:10 +00:00
|
|
|
OldValue = *PushLock;
|
2006-01-03 23:36:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Break out of the loop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We'll have to create a Waitblock */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Flags = EX_PUSH_LOCK_FLAGS_WAIT;
|
|
|
|
WaitBlock->ShareCount = 0;
|
2006-01-03 23:36:05 +00:00
|
|
|
NeedWake = FALSE;
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Previous = NULL;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Check if there is already a waiter */
|
|
|
|
if (OldValue.Waiting)
|
|
|
|
{
|
|
|
|
/* Set the current Wait Block pointer */
|
2010-01-13 22:35:43 +00:00
|
|
|
WaitBlock->Next = (PEX_PUSH_LOCK_WAIT_BLOCK)(
|
|
|
|
OldValue.Value &~ EX_PUSH_LOCK_PTR_BITS);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Nobody is the last waiter yet */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Last = NULL;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Point to ours */
|
|
|
|
NewValue.Value = (OldValue.Value & (EX_PUSH_LOCK_MULTIPLE_SHARED |
|
|
|
|
EX_PUSH_LOCK_LOCK)) |
|
|
|
|
EX_PUSH_LOCK_WAKING |
|
|
|
|
EX_PUSH_LOCK_WAITING |
|
2012-04-03 13:27:45 +00:00
|
|
|
(ULONG_PTR)WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Check if the pushlock was already waking */
|
2007-04-11 20:00:53 +00:00
|
|
|
if (!OldValue.Waking) NeedWake = TRUE;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We are the first waiter, so loop the wait block */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Last = WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Point to our wait block */
|
2007-04-11 20:00:53 +00:00
|
|
|
NewValue.Value = (OldValue.Value & EX_PUSH_LOCK_PTR_BITS) |
|
2006-01-03 23:36:05 +00:00
|
|
|
EX_PUSH_LOCK_WAITING |
|
2012-04-03 13:27:45 +00:00
|
|
|
(ULONG_PTR)WaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waiting);
|
|
|
|
|
|
|
|
#if DBG
|
|
|
|
/* Setup the Debug Wait Block */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock->Signaled = 0;
|
|
|
|
WaitBlock->OldValue = OldValue;
|
|
|
|
WaitBlock->NewValue = NewValue;
|
|
|
|
WaitBlock->PushLock = PushLock;
|
2006-01-03 23:36:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Write the new value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2007-04-11 20:00:53 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Ptr != OldValue.Ptr)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Retry */
|
2008-06-18 11:34:10 +00:00
|
|
|
OldValue = *PushLock;
|
2006-01-03 23:36:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the value now */
|
|
|
|
OldValue = NewValue;
|
|
|
|
|
|
|
|
/* Check if the pushlock needed waking */
|
|
|
|
if (NeedWake)
|
|
|
|
{
|
|
|
|
/* Scan the Waiters and Wake PushLocks */
|
|
|
|
ExpOptimizePushLockList(PushLock, OldValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the Wait Gate */
|
2007-01-22 06:47:44 +00:00
|
|
|
KeInitializeGate(&WaitBlock->WakeGate);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2009-02-06 14:47:19 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2006-01-03 23:36:05 +00:00
|
|
|
/* Now spin on the push lock if necessary */
|
2009-02-06 14:47:19 +00:00
|
|
|
if (ExPushLockSpinCount)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2009-02-06 14:47:19 +00:00
|
|
|
ULONG i = ExPushLockSpinCount;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(*(volatile LONG *)&WaitBlock->Flags & EX_PUSH_LOCK_WAITING))
|
|
|
|
break;
|
|
|
|
|
|
|
|
YieldProcessor();
|
|
|
|
} while (--i);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
2009-02-06 14:47:19 +00:00
|
|
|
#endif
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Now try to remove the wait bit */
|
2007-01-22 06:47:44 +00:00
|
|
|
if (InterlockedBitTestAndReset(&WaitBlock->Flags, 1))
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Fast-path did not work, we need to do a full wait */
|
2007-01-22 06:47:44 +00:00
|
|
|
KeWaitForGate(&WaitBlock->WakeGate, WrPushLock, KernelMode);
|
|
|
|
ASSERT(WaitBlock->Signaled);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We shouldn't be shared anymore */
|
2007-01-22 06:47:44 +00:00
|
|
|
ASSERT((WaitBlock->ShareCount == 0));
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExfReleasePushLock
|
|
|
|
* @implemented NT5.1
|
|
|
|
*
|
2007-04-11 20:00:53 +00:00
|
|
|
* The ExReleasePushLock routine releases a previously acquired PushLock.
|
|
|
|
*
|
2006-01-03 23:36:05 +00:00
|
|
|
*
|
|
|
|
* @params PushLock
|
|
|
|
* Pointer to a previously acquired pushlock.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
2007-04-11 20:00:53 +00:00
|
|
|
* @remarks Callers of ExfReleasePushLock must be running at IRQL <= APC_LEVEL.
|
2006-01-03 23:36:05 +00:00
|
|
|
* This macro should usually be paired up with KeLeaveCriticalRegion.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfReleasePushLock(PEX_PUSH_LOCK PushLock)
|
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
EX_PUSH_LOCK OldValue = *PushLock, NewValue, WakeValue;
|
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock, LastWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(OldValue.Locked);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Start main loop */
|
|
|
|
while (TRUE)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Check if someone is waiting on the lock */
|
|
|
|
if (!OldValue.Waiting)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Check if it's shared */
|
|
|
|
if (OldValue.Shared > 1)
|
|
|
|
{
|
|
|
|
/* Write the Old Value but decrease share count */
|
|
|
|
NewValue = OldValue;
|
|
|
|
NewValue.Shared--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Simply clear the lock */
|
|
|
|
NewValue.Value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the New Value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
2007-04-11 20:00:53 +00:00
|
|
|
if (NewValue.Value == OldValue.Value) return;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Did it enter a wait state? */
|
|
|
|
OldValue = NewValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Ok, we do know someone is waiting on it. Are there more then one? */
|
|
|
|
if (OldValue.MultipleShared)
|
|
|
|
{
|
|
|
|
/* Get the wait block */
|
2010-01-13 22:35:43 +00:00
|
|
|
WaitBlock = (PEX_PUSH_LOCK_WAIT_BLOCK)(OldValue.Value &
|
2008-04-01 18:14:01 +00:00
|
|
|
~EX_PUSH_LOCK_PTR_BITS);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Loop until we find the last wait block */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Get the last wait block */
|
|
|
|
LastWaitBlock = WaitBlock->Last;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Did it exist? */
|
|
|
|
if (LastWaitBlock)
|
|
|
|
{
|
|
|
|
/* Choose it */
|
|
|
|
WaitBlock = LastWaitBlock;
|
|
|
|
break;
|
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Keep searching */
|
|
|
|
WaitBlock = WaitBlock->Next;
|
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Make sure the Share Count is above 0 */
|
|
|
|
if (WaitBlock->ShareCount > 0)
|
|
|
|
{
|
|
|
|
/* This shouldn't be an exclusive wait block */
|
|
|
|
ASSERT(WaitBlock->Flags & EX_PUSH_LOCK_FLAGS_EXCLUSIVE);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Do the decrease and check if the lock isn't shared anymore */
|
|
|
|
if (InterlockedDecrement(&WaitBlock->ShareCount) > 0) return;
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
[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
|
|
|
/*
|
2008-04-01 18:14:01 +00:00
|
|
|
* If nobody was waiting on the block, then we possibly reduced the number
|
|
|
|
* of times the pushlock was shared, and we unlocked it.
|
|
|
|
* If someone was waiting, and more then one person is waiting, then we
|
|
|
|
* reduced the number of times the pushlock is shared in the wait block.
|
|
|
|
* Therefore, at this point, we can now 'satisfy' the wait.
|
|
|
|
*/
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Now we need to see if it's waking */
|
|
|
|
if (OldValue.Waking)
|
|
|
|
{
|
|
|
|
/* Remove the lock and multiple shared bits */
|
|
|
|
NewValue.Value = OldValue.Value;
|
|
|
|
NewValue.MultipleShared = FALSE;
|
|
|
|
NewValue.Locked = FALSE;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waking && !NewValue.Locked && !NewValue.MultipleShared);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Write the new value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2008-04-01 18:14:01 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value == OldValue.Value) return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove the lock and multiple shared bits */
|
|
|
|
NewValue.Value = OldValue.Value;
|
|
|
|
NewValue.MultipleShared = FALSE;
|
|
|
|
NewValue.Locked = FALSE;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* It's not already waking, so add the wake bit */
|
|
|
|
NewValue.Waking = TRUE;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waking && !NewValue.Locked && !NewValue.MultipleShared);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Write the new value */
|
|
|
|
WakeValue = NewValue;
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2008-04-01 18:14:01 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value != OldValue.Value) continue;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* The write was successful. The pushlock is Unlocked and Waking */
|
|
|
|
ExfWakePushLock(PushLock, WakeValue);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExfReleasePushLockShared
|
|
|
|
* @implemented NT5.2
|
|
|
|
*
|
|
|
|
* The ExfReleasePushLockShared macro releases a previously acquired PushLock.
|
|
|
|
*
|
|
|
|
* @params PushLock
|
|
|
|
* Pointer to a previously acquired pushlock.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks Callers of ExReleasePushLockShared must be running at IRQL <= APC_LEVEL.
|
|
|
|
* This macro should usually be paired up with KeLeaveCriticalRegion.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfReleasePushLockShared(PEX_PUSH_LOCK PushLock)
|
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
EX_PUSH_LOCK OldValue = *PushLock, NewValue, WakeValue;
|
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock, LastWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Check if someone is waiting on the lock */
|
2007-04-11 20:00:53 +00:00
|
|
|
while (!OldValue.Waiting)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Check if it's shared */
|
|
|
|
if (OldValue.Shared > 1)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Write the Old Value but decrease share count */
|
|
|
|
NewValue = OldValue;
|
|
|
|
NewValue.Shared--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Simply clear the lock */
|
|
|
|
NewValue.Value = 0;
|
|
|
|
}
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Write the New Value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2007-04-11 20:00:53 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value == OldValue.Value) return;
|
2006-01-03 23:36:05 +00:00
|
|
|
|
2007-04-11 20:00:53 +00:00
|
|
|
/* Did it enter a wait state? */
|
|
|
|
OldValue = NewValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ok, we do know someone is waiting on it. Are there more then one? */
|
|
|
|
if (OldValue.MultipleShared)
|
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Get the wait block */
|
2010-01-13 22:35:43 +00:00
|
|
|
WaitBlock = (PEX_PUSH_LOCK_WAIT_BLOCK)(OldValue.Value &
|
2008-04-01 18:14:01 +00:00
|
|
|
~EX_PUSH_LOCK_PTR_BITS);
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Loop until we find the last wait block */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Get the last wait block */
|
|
|
|
LastWaitBlock = WaitBlock->Last;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Did it exist? */
|
|
|
|
if (LastWaitBlock)
|
|
|
|
{
|
|
|
|
/* Choose it */
|
|
|
|
WaitBlock = LastWaitBlock;
|
|
|
|
break;
|
|
|
|
}
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Keep searching */
|
|
|
|
WaitBlock = WaitBlock->Next;
|
|
|
|
}
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(WaitBlock->ShareCount > 0);
|
2007-04-11 20:00:53 +00:00
|
|
|
ASSERT(WaitBlock->Flags & EX_PUSH_LOCK_FLAGS_EXCLUSIVE);
|
2006-01-03 23:36:05 +00:00
|
|
|
|
|
|
|
/* Do the decrease and check if the lock isn't shared anymore */
|
2007-04-11 20:00:53 +00:00
|
|
|
if (InterlockedDecrement(&WaitBlock->ShareCount) > 0) return;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
[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
|
|
|
/*
|
2006-01-03 23:36:05 +00:00
|
|
|
* If nobody was waiting on the block, then we possibly reduced the number
|
|
|
|
* of times the pushlock was shared, and we unlocked it.
|
|
|
|
* If someone was waiting, and more then one person is waiting, then we
|
|
|
|
* reduced the number of times the pushlock is shared in the wait block.
|
|
|
|
* Therefore, at this point, we can now 'satisfy' the wait.
|
|
|
|
*/
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Now we need to see if it's waking */
|
|
|
|
if (OldValue.Waking)
|
|
|
|
{
|
|
|
|
/* Remove the lock and multiple shared bits */
|
|
|
|
NewValue.Value = OldValue.Value;
|
|
|
|
NewValue.MultipleShared = FALSE;
|
|
|
|
NewValue.Locked = FALSE;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waking && !NewValue.Locked && !NewValue.MultipleShared);
|
|
|
|
|
|
|
|
/* Write the new value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
2007-04-11 20:00:53 +00:00
|
|
|
if (NewValue.Value == OldValue.Value) return;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove the lock and multiple shared bits */
|
|
|
|
NewValue.Value = OldValue.Value;
|
|
|
|
NewValue.MultipleShared = FALSE;
|
|
|
|
NewValue.Locked = FALSE;
|
|
|
|
|
|
|
|
/* It's not already waking, so add the wake bit */
|
|
|
|
NewValue.Waking = TRUE;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waking && !NewValue.Locked && !NewValue.MultipleShared);
|
|
|
|
|
|
|
|
/* Write the new value */
|
2008-04-01 18:14:01 +00:00
|
|
|
WakeValue = NewValue;
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
if (NewValue.Value != OldValue.Value) continue;
|
|
|
|
|
|
|
|
/* The write was successful. The pushlock is Unlocked and Waking */
|
2008-04-01 18:14:01 +00:00
|
|
|
ExfWakePushLock(PushLock, WakeValue);
|
2007-04-11 20:00:53 +00:00
|
|
|
return;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* ExfReleasePushLockExclusive
|
|
|
|
* @implemented NT5.2
|
|
|
|
*
|
|
|
|
* The ExfReleasePushLockExclusive routine releases a previously
|
|
|
|
* exclusively acquired PushLock.
|
|
|
|
*
|
|
|
|
* @params PushLock
|
|
|
|
* Pointer to a previously acquired pushlock.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks Callers of ExReleasePushLockExclusive must be running at IRQL <= APC_LEVEL.
|
|
|
|
* This macro should usually be paired up with KeLeaveCriticalRegion.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
|
|
|
|
{
|
2007-01-22 06:47:44 +00:00
|
|
|
EX_PUSH_LOCK NewValue, WakeValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
EX_PUSH_LOCK OldValue = *PushLock;
|
|
|
|
|
|
|
|
/* Loop until we can change */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(OldValue.Locked);
|
|
|
|
ASSERT(OldValue.Waiting || OldValue.Shared == 0);
|
|
|
|
|
|
|
|
/* Check if it's waiting and not yet waking */
|
|
|
|
if ((OldValue.Waiting) && !(OldValue.Waking))
|
|
|
|
{
|
|
|
|
/* Remove the lock bit, and add the wake bit */
|
|
|
|
NewValue.Value = (OldValue.Value &~ EX_PUSH_LOCK_LOCK) |
|
|
|
|
EX_PUSH_LOCK_WAKING;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waking && !NewValue.Locked);
|
|
|
|
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Write the New Value. Save our original value for waking */
|
|
|
|
WakeValue = NewValue;
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
|
|
|
|
/* Check if the value changed behind our back */
|
2008-06-18 11:34:10 +00:00
|
|
|
if (NewValue.Value == OldValue.Value)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2007-01-22 06:47:44 +00:00
|
|
|
/* Wake the Pushlock */
|
|
|
|
ExfWakePushLock(PushLock, WakeValue);
|
|
|
|
break;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* A simple unlock */
|
|
|
|
NewValue.Value = OldValue.Value &~ EX_PUSH_LOCK_LOCK;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NewValue.Waking && !NewValue.Waiting);
|
|
|
|
|
|
|
|
/* Write the New Value */
|
2010-01-13 22:35:43 +00:00
|
|
|
NewValue.Ptr = InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2006-01-03 23:36:05 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr);
|
|
|
|
|
|
|
|
/* Check if the value changed behind our back */
|
|
|
|
if (NewValue.Value == OldValue.Value) break;
|
|
|
|
}
|
2007-01-22 06:47:44 +00:00
|
|
|
|
|
|
|
/* Loop again */
|
|
|
|
OldValue = NewValue;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExfTryToWakePushLock
|
|
|
|
* @implemented NT5.2
|
|
|
|
*
|
|
|
|
* The ExfTryToWakePushLock attemps to wake a waiting pushlock.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a PushLock which is in the wait state.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks The pushlock must be in a wait state and must not be already waking.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfTryToWakePushLock(PEX_PUSH_LOCK PushLock)
|
|
|
|
{
|
|
|
|
EX_PUSH_LOCK OldValue = *PushLock, NewValue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the Pushlock is not waiting on anything, or if it's already waking up
|
|
|
|
* and locked, don't do anything
|
|
|
|
*/
|
2008-04-01 18:14:01 +00:00
|
|
|
if ((OldValue.Waking) || (OldValue.Locked) || !(OldValue.Waiting)) return;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Make it Waking */
|
|
|
|
NewValue = OldValue;
|
|
|
|
NewValue.Waking = TRUE;
|
2012-04-03 13:27:45 +00:00
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Write the New Value */
|
2010-01-13 22:35:43 +00:00
|
|
|
if (InterlockedCompareExchangePointer(&PushLock->Ptr,
|
2008-04-01 18:14:01 +00:00
|
|
|
NewValue.Ptr,
|
|
|
|
OldValue.Ptr) == OldValue.Ptr)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Wake the Pushlock */
|
|
|
|
ExfWakePushLock(PushLock, NewValue);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name ExfUnblockPushLock
|
|
|
|
* @implemented NT5.1
|
|
|
|
*
|
|
|
|
* The ExfUnblockPushLock routine unblocks a previously blocked PushLock.
|
|
|
|
*
|
|
|
|
* @param PushLock
|
|
|
|
* Pointer to a previously blocked PushLock.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks Callers of ExfUnblockPushLock can be running at any IRQL.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExfUnblockPushLock(PEX_PUSH_LOCK PushLock,
|
|
|
|
PVOID CurrentWaitBlock)
|
|
|
|
{
|
|
|
|
PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock, NextWaitBlock;
|
|
|
|
KIRQL OldIrql = DISPATCH_LEVEL;
|
|
|
|
|
|
|
|
/* Get the wait block and erase the previous one */
|
2007-01-22 06:47:44 +00:00
|
|
|
WaitBlock = InterlockedExchangePointer(&PushLock->Ptr, NULL);
|
2006-01-03 23:36:05 +00:00
|
|
|
if (WaitBlock)
|
|
|
|
{
|
|
|
|
/* Check if there is a linked pushlock and raise IRQL appropriately */
|
|
|
|
if (WaitBlock->Next) KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
|
|
|
|
|
|
|
|
/* Start block loop */
|
2008-04-01 18:14:01 +00:00
|
|
|
while (WaitBlock)
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Get the next block */
|
|
|
|
NextWaitBlock = WaitBlock->Next;
|
|
|
|
|
|
|
|
/* Remove the wait flag from the Wait block */
|
2008-04-01 18:14:01 +00:00
|
|
|
if (!InterlockedBitTestAndReset(&WaitBlock->Flags, EX_PUSH_LOCK_FLAGS_WAIT_V))
|
2006-01-03 23:36:05 +00:00
|
|
|
{
|
|
|
|
/* Nobody removed the flag before us, so signal the event */
|
2007-01-22 06:47:44 +00:00
|
|
|
KeSetEventBoostPriority(&WaitBlock->WakeEvent, NULL);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 18:14:01 +00:00
|
|
|
/* Try the next one */
|
|
|
|
WaitBlock = NextWaitBlock;
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lower IRQL if needed */
|
|
|
|
if (OldIrql != DISPATCH_LEVEL) KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we got a wait block that's pending */
|
|
|
|
if ((CurrentWaitBlock) &&
|
|
|
|
(((PEX_PUSH_LOCK_WAIT_BLOCK)CurrentWaitBlock)->Flags &
|
|
|
|
EX_PUSH_LOCK_FLAGS_WAIT))
|
|
|
|
{
|
|
|
|
/* Wait for the pushlock to be unblocked */
|
2007-01-22 06:47:44 +00:00
|
|
|
ExWaitForUnblockPushLock(PushLock, CurrentWaitBlock);
|
2006-01-03 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|