From f3c9b196a6e59273fbc883630549fa931e59a69b Mon Sep 17 00:00:00 2001 From: Gunnar Dalsnes Date: Sun, 18 Jan 2004 22:41:53 +0000 Subject: [PATCH] added KiAcquire/ReleaseSpinLock svn path=/trunk/; revision=7759 --- reactos/include/ddk/kefuncs.h | 8 +++- reactos/ntoskrnl/ke/spinlock.c | 88 +++++++++++++++++++++------------- reactos/ntoskrnl/ntoskrnl.def | 6 +-- reactos/ntoskrnl/ntoskrnl.edf | 6 +-- 4 files changed, 67 insertions(+), 41 deletions(-) diff --git a/reactos/include/ddk/kefuncs.h b/reactos/include/ddk/kefuncs.h index 548856c2f39..cf820069b8b 100644 --- a/reactos/include/ddk/kefuncs.h +++ b/reactos/include/ddk/kefuncs.h @@ -10,6 +10,10 @@ VOID STDCALL KeAttachProcess (struct _EPROCESS* Process); +VOID FASTCALL KiAcquireSpinLock(PKSPIN_LOCK SpinLock); + +VOID FASTCALL KiReleaseSpinLock(PKSPIN_LOCK SpinLock); + VOID KeDrainApcQueue(VOID); struct _KPROCESS* KeGetCurrentProcess(VOID); @@ -516,8 +520,8 @@ KfReleaseSpinLock ( VOID STDCALL KiDeliverApc(ULONG Unknown1, - ULONG Unknown2, - ULONG Unknown3); + ULONG Unknown2, + ULONG Unknown3); VOID STDCALL KiDispatchInterrupt(VOID); diff --git a/reactos/ntoskrnl/ke/spinlock.c b/reactos/ntoskrnl/ke/spinlock.c index 5e4617395c6..3fef79b096c 100644 --- a/reactos/ntoskrnl/ke/spinlock.c +++ b/reactos/ntoskrnl/ke/spinlock.c @@ -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 * PROJECT: ReactOS kernel @@ -44,12 +44,12 @@ KeSynchronizeExecution (PKINTERRUPT Interrupt, KIRQL oldlvl; BOOLEAN ret; - KeRaiseIrql(Interrupt->SynchLevel,&oldlvl); - KeAcquireSpinLockAtDpcLevel(Interrupt->IrqLock); + KeRaiseIrql(Interrupt->SynchLevel, &oldlvl); + KiAcquireSpinLock(Interrupt->IrqLock); ret = SynchronizeRoutine(SynchronizeContext); - KeReleaseSpinLockFromDpcLevel(Interrupt->IrqLock); + KiReleaseSpinLock(Interrupt->IrqLock); KeLowerIrql(oldlvl); return(ret); @@ -77,27 +77,8 @@ KeInitializeSpinLock (PKSPIN_LOCK SpinLock) VOID FASTCALL KefAcquireSpinLockAtDpcLevel(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 */ - } + assert(KeGetCurrentIrql() == DISPATCH_LEVEL); + KiAcquireSpinLock(SpinLock); } #undef KeAcquireSpinLockAtDpcLevel @@ -114,7 +95,7 @@ KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK SpinLock) * SpinLock = Spinlock to acquire */ { - KefAcquireSpinLockAtDpcLevel(SpinLock); + KefAcquireSpinLockAtDpcLevel(SpinLock); } #undef KefReleaseSpinLockFromDpcLevel @@ -125,12 +106,8 @@ KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK SpinLock) VOID FASTCALL KefReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock) { - if (*SpinLock != 1) - { - DbgPrint("Releasing unacquired spinlock %x\n", SpinLock); - KEBUGCHECK(0); - } - (void)InterlockedExchange((LONG *)SpinLock, 0); + assert(KeGetCurrentIrql() == DISPATCH_LEVEL); + KiReleaseSpinLock(SpinLock); } #undef KeReleaseSpinLockFromDpcLevel @@ -147,7 +124,52 @@ KeReleaseSpinLockFromDpcLevel (PKSPIN_LOCK SpinLock) * 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 */ diff --git a/reactos/ntoskrnl/ntoskrnl.def b/reactos/ntoskrnl/ntoskrnl.def index 329426af368..c7d2763525c 100644 --- a/reactos/ntoskrnl/ntoskrnl.def +++ b/reactos/ntoskrnl/ntoskrnl.def @@ -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 ; @@ -475,14 +475,14 @@ KeWaitForSingleObject@20 ;@KefAcquireSpinLockAtDpcLevel ;@KefReleaseSpinLockFromDpcLevel ;Kei386EoiHelper -;@KiAcquireSpinLock@4 +@KiAcquireSpinLock@4 ;KiBugCheckData DATA ;KiCoprocessorError@0 KiDeliverApc@12 KiDispatchInterrupt@0 KiInterruptDispatch2@8 ;KiIpiServiceRoutine@8 -;@KiReleaseSpinLock@4 +@KiReleaseSpinLock@4 ;KiUnexpectedInterrupt ;Kii386SpinOnSpinLock KiRawTicks DATA diff --git a/reactos/ntoskrnl/ntoskrnl.edf b/reactos/ntoskrnl/ntoskrnl.edf index 25021e2ad7e..91906999cf2 100644 --- a/reactos/ntoskrnl/ntoskrnl.edf +++ b/reactos/ntoskrnl/ntoskrnl.edf @@ -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 ; @@ -476,14 +476,14 @@ KeWaitForSingleObject=KeWaitForSingleObject@20 KefAcquireSpinLockAtDpcLevel=@KefAcquireSpinLockAtDpcLevel@4 KefReleaseSpinLockFromDpcLevel=@KefReleaseSpinLockFromDpcLevel@4 ;Kei386EoiHelper -;KiAcquireSpinLock@4 +KiAcquireSpinLock=@KiAcquireSpinLock@4 ;KiBugCheckData DATA ;KiCoprocessorError@0 KiDeliverApc=KiDeliverApc@12 KiDispatchInterrupt=KiDispatchInterrupt@0 KiInterruptDispatch2=KiInterruptDispatch2@8 ;KiIpiServiceRoutine@8 -;KiReleaseSpinLock@4 +KiReleaseSpinLock=@KiReleaseSpinLock@4 ;KiUnexpectedInterrupt ;Kii386SpinOnSpinLock KiRawTicks DATA