added KiAcquire/ReleaseSpinLock

svn path=/trunk/; revision=7759
This commit is contained in:
Gunnar Dalsnes 2004-01-18 22:41:53 +00:00
parent 68ac8c2fb9
commit f3c9b196a6
4 changed files with 67 additions and 41 deletions

View file

@ -10,6 +10,10 @@
VOID STDCALL KeAttachProcess (struct _EPROCESS* Process); VOID STDCALL KeAttachProcess (struct _EPROCESS* Process);
VOID FASTCALL KiAcquireSpinLock(PKSPIN_LOCK SpinLock);
VOID FASTCALL KiReleaseSpinLock(PKSPIN_LOCK SpinLock);
VOID KeDrainApcQueue(VOID); VOID KeDrainApcQueue(VOID);
struct _KPROCESS* KeGetCurrentProcess(VOID); struct _KPROCESS* KeGetCurrentProcess(VOID);
@ -516,8 +520,8 @@ KfReleaseSpinLock (
VOID STDCALL KiDeliverApc(ULONG Unknown1, VOID STDCALL KiDeliverApc(ULONG Unknown1,
ULONG Unknown2, ULONG Unknown2,
ULONG Unknown3); ULONG Unknown3);
VOID STDCALL KiDispatchInterrupt(VOID); VOID STDCALL KiDispatchInterrupt(VOID);

View file

@ -1,4 +1,4 @@
/* $Id: spinlock.c,v 1.19 2003/09/25 15:54:42 navaraf Exp $ /* $Id: spinlock.c,v 1.20 2004/01/18 22:41:53 gdalsnes Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -44,12 +44,12 @@ KeSynchronizeExecution (PKINTERRUPT Interrupt,
KIRQL oldlvl; KIRQL oldlvl;
BOOLEAN ret; BOOLEAN ret;
KeRaiseIrql(Interrupt->SynchLevel,&oldlvl); KeRaiseIrql(Interrupt->SynchLevel, &oldlvl);
KeAcquireSpinLockAtDpcLevel(Interrupt->IrqLock); KiAcquireSpinLock(Interrupt->IrqLock);
ret = SynchronizeRoutine(SynchronizeContext); ret = SynchronizeRoutine(SynchronizeContext);
KeReleaseSpinLockFromDpcLevel(Interrupt->IrqLock); KiReleaseSpinLock(Interrupt->IrqLock);
KeLowerIrql(oldlvl); KeLowerIrql(oldlvl);
return(ret); return(ret);
@ -77,27 +77,8 @@ KeInitializeSpinLock (PKSPIN_LOCK SpinLock)
VOID FASTCALL VOID FASTCALL
KefAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock) KefAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock)
{ {
ULONG i; assert(KeGetCurrentIrql() == DISPATCH_LEVEL);
KiAcquireSpinLock(SpinLock);
/*
* FIXME: This depends on gcc assembling this test to a single load from
* the spinlock's value.
*/
if (*SpinLock >= 2)
{
DbgPrint("Lock %x has bad value %x\n", SpinLock, *SpinLock);
KEBUGCHECK(0);
}
while ((i = InterlockedExchange((LONG *)SpinLock, 1)) == 1)
{
#ifndef MP
DbgPrint("Spinning on spinlock %x current value %x\n", SpinLock, i);
KEBUGCHECK(0);
#else /* not MP */
/* Avoid reading the value again too fast */
#endif /* MP */
}
} }
#undef KeAcquireSpinLockAtDpcLevel #undef KeAcquireSpinLockAtDpcLevel
@ -114,7 +95,7 @@ KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK SpinLock)
* SpinLock = Spinlock to acquire * SpinLock = Spinlock to acquire
*/ */
{ {
KefAcquireSpinLockAtDpcLevel(SpinLock); KefAcquireSpinLockAtDpcLevel(SpinLock);
} }
#undef KefReleaseSpinLockFromDpcLevel #undef KefReleaseSpinLockFromDpcLevel
@ -125,12 +106,8 @@ KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK SpinLock)
VOID FASTCALL VOID FASTCALL
KefReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock) KefReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock)
{ {
if (*SpinLock != 1) assert(KeGetCurrentIrql() == DISPATCH_LEVEL);
{ KiReleaseSpinLock(SpinLock);
DbgPrint("Releasing unacquired spinlock %x\n", SpinLock);
KEBUGCHECK(0);
}
(void)InterlockedExchange((LONG *)SpinLock, 0);
} }
#undef KeReleaseSpinLockFromDpcLevel #undef KeReleaseSpinLockFromDpcLevel
@ -147,7 +124,52 @@ KeReleaseSpinLockFromDpcLevel (PKSPIN_LOCK SpinLock)
* SpinLock = Spinlock to release * SpinLock = Spinlock to release
*/ */
{ {
KefReleaseSpinLockFromDpcLevel(SpinLock); KefReleaseSpinLockFromDpcLevel(SpinLock);
}
/*
* @implemented
*/
VOID FASTCALL
KiAcquireSpinLock(PKSPIN_LOCK SpinLock)
{
ULONG i;
/*
* FIXME: This depends on gcc assembling this test to a single load from
* the spinlock's value.
*/
if (*SpinLock >= 2)
{
DbgPrint("Lock %x has bad value %x\n", SpinLock, *SpinLock);
KEBUGCHECK(0);
}
while ((i = InterlockedExchange((LONG *)SpinLock, 1)) == 1)
{
#ifndef MP
DbgPrint("Spinning on spinlock %x current value %x\n", SpinLock, i);
KEBUGCHECK(0);
#else /* not MP */
/* Avoid reading the value again too fast */
#endif /* MP */
}
}
/*
* @implemented
*/
VOID FASTCALL
KiReleaseSpinLock(PKSPIN_LOCK SpinLock)
{
if (*SpinLock != 1)
{
DbgPrint("Releasing unacquired spinlock %x\n", SpinLock);
KEBUGCHECK(0);
}
(void)InterlockedExchange((LONG *)SpinLock, 0);
} }
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.def,v 1.171 2003/12/31 05:33:03 jfilby Exp $ ; $Id: ntoskrnl.def,v 1.172 2004/01/18 22:34:05 gdalsnes Exp $
; ;
; reactos/ntoskrnl/ntoskrnl.def ; reactos/ntoskrnl/ntoskrnl.def
; ;
@ -475,14 +475,14 @@ KeWaitForSingleObject@20
;@KefAcquireSpinLockAtDpcLevel ;@KefAcquireSpinLockAtDpcLevel
;@KefReleaseSpinLockFromDpcLevel ;@KefReleaseSpinLockFromDpcLevel
;Kei386EoiHelper ;Kei386EoiHelper
;@KiAcquireSpinLock@4 @KiAcquireSpinLock@4
;KiBugCheckData DATA ;KiBugCheckData DATA
;KiCoprocessorError@0 ;KiCoprocessorError@0
KiDeliverApc@12 KiDeliverApc@12
KiDispatchInterrupt@0 KiDispatchInterrupt@0
KiInterruptDispatch2@8 KiInterruptDispatch2@8
;KiIpiServiceRoutine@8 ;KiIpiServiceRoutine@8
;@KiReleaseSpinLock@4 @KiReleaseSpinLock@4
;KiUnexpectedInterrupt ;KiUnexpectedInterrupt
;Kii386SpinOnSpinLock ;Kii386SpinOnSpinLock
KiRawTicks DATA KiRawTicks DATA

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.edf,v 1.158 2003/12/31 05:33:03 jfilby Exp $ ; $Id: ntoskrnl.edf,v 1.159 2004/01/18 22:34:05 gdalsnes Exp $
; ;
; reactos/ntoskrnl/ntoskrnl.def ; reactos/ntoskrnl/ntoskrnl.def
; ;
@ -476,14 +476,14 @@ KeWaitForSingleObject=KeWaitForSingleObject@20
KefAcquireSpinLockAtDpcLevel=@KefAcquireSpinLockAtDpcLevel@4 KefAcquireSpinLockAtDpcLevel=@KefAcquireSpinLockAtDpcLevel@4
KefReleaseSpinLockFromDpcLevel=@KefReleaseSpinLockFromDpcLevel@4 KefReleaseSpinLockFromDpcLevel=@KefReleaseSpinLockFromDpcLevel@4
;Kei386EoiHelper ;Kei386EoiHelper
;KiAcquireSpinLock@4 KiAcquireSpinLock=@KiAcquireSpinLock@4
;KiBugCheckData DATA ;KiBugCheckData DATA
;KiCoprocessorError@0 ;KiCoprocessorError@0
KiDeliverApc=KiDeliverApc@12 KiDeliverApc=KiDeliverApc@12
KiDispatchInterrupt=KiDispatchInterrupt@0 KiDispatchInterrupt=KiDispatchInterrupt@0
KiInterruptDispatch2=KiInterruptDispatch2@8 KiInterruptDispatch2=KiInterruptDispatch2@8
;KiIpiServiceRoutine@8 ;KiIpiServiceRoutine@8
;KiReleaseSpinLock@4 KiReleaseSpinLock=@KiReleaseSpinLock@4
;KiUnexpectedInterrupt ;KiUnexpectedInterrupt
;Kii386SpinOnSpinLock ;Kii386SpinOnSpinLock
KiRawTicks DATA KiRawTicks DATA