2010-07-24 01:12:13 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS HAL
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: hal/halx86/up/spinlock.c
|
|
|
|
* PURPOSE: Spinlock and Queued Spinlock Support
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#undef KeAcquireSpinLock
|
|
|
|
#undef KeReleaseSpinLock
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
KIRQL
|
|
|
|
KeAcquireSpinLockRaiseToSynch(PKSPIN_LOCK SpinLock)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Raise to sync */
|
|
|
|
KeRaiseIrql(SYNCH_LEVEL, &OldIrql);
|
|
|
|
|
|
|
|
/* Acquire the lock and return */
|
|
|
|
KxAcquireSpinLock(SpinLock);
|
2010-07-24 01:12:13 +00:00
|
|
|
return OldIrql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
KIRQL
|
|
|
|
NTAPI
|
|
|
|
KeAcquireSpinLockRaiseToDpc(PKSPIN_LOCK SpinLock)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Raise to dispatch */
|
2010-07-24 01:12:13 +00:00
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Acquire the lock and return */
|
|
|
|
KxAcquireSpinLock(SpinLock);
|
2010-07-24 01:12:13 +00:00
|
|
|
return OldIrql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KeReleaseSpinLock(PKSPIN_LOCK SpinLock,
|
|
|
|
KIRQL OldIrql)
|
|
|
|
{
|
2011-06-04 12:33:54 +00:00
|
|
|
/* Release the lock and lower IRQL back */
|
|
|
|
KxReleaseSpinLock(SpinLock);
|
2010-07-24 01:12:13 +00:00
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
KIRQL
|
|
|
|
KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Raise to dispatch */
|
2010-07-24 01:12:13 +00:00
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Acquire the lock */
|
|
|
|
KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
|
2010-07-24 01:12:13 +00:00
|
|
|
return OldIrql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
KIRQL
|
|
|
|
KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Raise to synch */
|
|
|
|
KeRaiseIrql(SYNCH_LEVEL, &OldIrql);
|
|
|
|
|
|
|
|
/* Acquire the lock */
|
|
|
|
KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
|
2010-07-24 01:12:13 +00:00
|
|
|
return OldIrql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN PKLOCK_QUEUE_HANDLE LockHandle)
|
|
|
|
{
|
2011-06-04 12:33:54 +00:00
|
|
|
/* Set up the lock */
|
|
|
|
LockHandle->LockQueue.Next = NULL;
|
|
|
|
LockHandle->LockQueue.Lock = SpinLock;
|
|
|
|
|
|
|
|
/* Raise to dispatch */
|
2010-07-24 01:12:13 +00:00
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, &LockHandle->OldIrql);
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Acquire the lock */
|
|
|
|
KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
|
2010-07-24 01:12:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 12:33:54 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
KeAcquireInStackQueuedSpinLockRaiseToSynch(IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN PKLOCK_QUEUE_HANDLE LockHandle)
|
|
|
|
{
|
2011-06-04 12:33:54 +00:00
|
|
|
/* Set up the lock */
|
|
|
|
LockHandle->LockQueue.Next = NULL;
|
|
|
|
LockHandle->LockQueue.Lock = SpinLock;
|
|
|
|
|
|
|
|
/* Raise to synch */
|
2010-07-24 01:12:13 +00:00
|
|
|
KeRaiseIrql(SYNCH_LEVEL, &LockHandle->OldIrql);
|
2011-06-04 12:33:54 +00:00
|
|
|
|
|
|
|
/* Acquire the lock */
|
|
|
|
KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
|
2010-07-24 01:12:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 12:33:54 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber,
|
|
|
|
IN KIRQL OldIrql)
|
|
|
|
{
|
2011-06-04 12:33:54 +00:00
|
|
|
/* Release the lock */
|
|
|
|
KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
|
|
|
|
|
|
|
|
/* Lower IRQL back */
|
2010-07-24 01:12:13 +00:00
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
2011-06-04 12:33:54 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
|
|
|
|
{
|
|
|
|
/* Simply lower IRQL back */
|
2011-06-04 12:33:54 +00:00
|
|
|
KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
|
2010-07-24 01:12:13 +00:00
|
|
|
KeLowerIrql(LockHandle->OldIrql);
|
|
|
|
}
|
|
|
|
|
2011-06-04 12:33:54 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
KeTryToAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber,
|
|
|
|
IN PKIRQL OldIrql)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
/* Simply raise to dispatch */
|
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, OldIrql);
|
|
|
|
|
2011-06-04 12:33:54 +00:00
|
|
|
/* Add an explicit memory barrier to prevent the compiler from reordering
|
|
|
|
memory accesses across the borders of spinlocks */
|
2011-06-04 15:42:32 +00:00
|
|
|
KeMemoryBarrierWithoutFence();
|
2011-06-04 12:33:54 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Always return true on UP Machines */
|
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
UNIMPLEMENTED;
|
2011-06-04 12:33:54 +00:00
|
|
|
ASSERT(FALSE);
|
2010-07-24 01:12:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
LOGICAL
|
|
|
|
KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber,
|
|
|
|
OUT PKIRQL OldIrql)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
/* Simply raise to dispatch */
|
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, OldIrql);
|
|
|
|
|
2011-06-04 12:33:54 +00:00
|
|
|
/* Add an explicit memory barrier to prevent the compiler from reordering
|
|
|
|
memory accesses across the borders of spinlocks */
|
2011-06-04 15:42:32 +00:00
|
|
|
KeMemoryBarrierWithoutFence();
|
2011-06-04 12:33:54 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Always return true on UP Machines */
|
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
UNIMPLEMENTED;
|
2011-06-04 12:33:54 +00:00
|
|
|
ASSERT(FALSE);
|
2010-07-24 01:12:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|