2007-09-03 01:57:36 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS HAL
|
2015-11-04 13:30:52 +00:00
|
|
|
* FILE: hal/halppc/generic/fmutex.c
|
2007-09-03 01:57:36 +00:00
|
|
|
* PURPOSE: Deprecated HAL Fast Mutex
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: Even HAL itself has #defines to use the Exi* APIs inside NTOSKRNL.
|
|
|
|
* These are only exported here for compatibility with really old
|
|
|
|
* drivers. Also note that in theory, these can be made much faster
|
|
|
|
* by using assembly and inlining all the operations, including
|
|
|
|
* raising and lowering irql.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <hal.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#undef ExAcquireFastMutex
|
|
|
|
#undef ExReleaseFastMutex
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExAcquireFastMutex(PFAST_MUTEX FastMutex)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Raise IRQL to APC */
|
|
|
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
|
|
|
|
|
|
|
/* Decrease the count */
|
|
|
|
if (InterlockedDecrement(&FastMutex->Count))
|
|
|
|
{
|
|
|
|
/* Someone is still holding it, use slow path */
|
|
|
|
FastMutex->Contention++;
|
2010-03-03 16:03:14 +00:00
|
|
|
KeWaitForSingleObject(&FastMutex->Event,
|
2007-09-03 01:57:36 +00:00
|
|
|
WrExecutive,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the owner and IRQL */
|
|
|
|
FastMutex->Owner = KeGetCurrentThread();
|
|
|
|
FastMutex->OldIrql = OldIrql;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
ExReleaseFastMutex(PFAST_MUTEX FastMutex)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Erase the owner */
|
|
|
|
FastMutex->Owner = (PVOID)1;
|
|
|
|
OldIrql = FastMutex->OldIrql;
|
|
|
|
|
|
|
|
/* Increase the count */
|
|
|
|
if (InterlockedIncrement(&FastMutex->Count) <= 0)
|
|
|
|
{
|
|
|
|
/* Someone was waiting for it, signal the waiter */
|
2010-03-03 16:03:14 +00:00
|
|
|
KeSetEventBoostPriority(&FastMutex->Event, IO_NO_INCREMENT);
|
2007-09-03 01:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lower IRQL back */
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
FASTCALL
|
|
|
|
ExiTryToAcquireFastMutex(PFAST_MUTEX FastMutex)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Raise to APC_LEVEL */
|
|
|
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
|
|
|
|
|
|
|
/* Check if we can quickly acquire it */
|
|
|
|
if (InterlockedCompareExchange(&FastMutex->Count, 0, 1) == 1)
|
|
|
|
{
|
|
|
|
/* We have, set us as owners */
|
|
|
|
FastMutex->Owner = KeGetCurrentThread();
|
|
|
|
FastMutex->OldIrql = OldIrql;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Acquire attempt failed */
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|