Author: tkreuzer
Date: Thu Jan 21 23:34:01 2010
New Revision: 45196
URL:
http://svn.reactos.org/svn/reactos?rev=45196&view=rev
Log:
Merge from amd64-branch:
44886 KxAcquireSpinLock: check for already owned lock only on debug builds, fix check in
inner loop, don't call Kii386SpinOnSpinLock inside the inner loop, but instead of it,
simplify the code. Stubplement Kii386SpinOnSpinLock in C
44893 Move spinlock inline functions into their own header, so they can be shared with
hal.
Added:
trunk/reactos/ntoskrnl/include/internal/spinlock.h
- copied unchanged from r44893,
branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/spinlock.h
Modified:
trunk/reactos/ntoskrnl/include/internal/ke_x.h
trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h
trunk/reactos/ntoskrnl/ke/spinlock.c
Modified: trunk/reactos/ntoskrnl/include/internal/ke_x.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ke_x.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ke_x.h [iso-8859-1] Thu Jan 21 23:34:01 2010
@@ -102,27 +102,6 @@
}
#ifndef CONFIG_SMP
-//
-// Spinlock Acquire at IRQL >= DISPATCH_LEVEL
-//
-FORCEINLINE
-VOID
-KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
-{
- /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
- UNREFERENCED_PARAMETER(SpinLock);
-}
-
-//
-// Spinlock Release at IRQL >= DISPATCH_LEVEL
-//
-FORCEINLINE
-VOID
-KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
-{
- /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
- UNREFERENCED_PARAMETER(SpinLock);
-}
//
// This routine protects against multiple CPU acquires, it's meaningless on UP.
@@ -302,72 +281,6 @@
}
#else
-
-//
-// Spinlock Acquisition at IRQL >= DISPATCH_LEVEL
-//
-FORCEINLINE
-VOID
-KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
-{
- /* Make sure that we don't own the lock already */
- if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock)
- {
- /* We do, bugcheck! */
- KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
- }
-
- /* Start acquire loop */
- for (;;)
- {
- /* Try to acquire it */
- if (InterlockedBitTestAndSet((PLONG)SpinLock, 0))
- {
- /* Value changed... wait until it's unlocked */
- while (*(volatile KSPIN_LOCK *)SpinLock == 1)
- {
-#if DBG
- /* On debug builds, we use a much slower but useful routine */
- //Kii386SpinOnSpinLock(SpinLock, 5);
-
- /* FIXME: Do normal yield for now */
- YieldProcessor();
-#else
- /* Otherwise, just yield and keep looping */
- YieldProcessor();
-#endif
- }
- }
- else
- {
-#if DBG
- /* On debug builds, we OR in the KTHREAD */
- *SpinLock = (KSPIN_LOCK)KeGetCurrentThread() | 1;
-#endif
- /* All is well, break out */
- break;
- }
- }
-}
-
-//
-// Spinlock Release at IRQL >= DISPATCH_LEVEL
-//
-FORCEINLINE
-VOID
-KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
-{
-#if DBG
- /* Make sure that the threads match */
- if (((KSPIN_LOCK)KeGetCurrentThread() | 1) != *SpinLock)
- {
- /* They don't, bugcheck */
- KeBugCheckEx(SPIN_LOCK_NOT_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
- }
-#endif
- /* Clear the lock */
- InterlockedAnd((PLONG)SpinLock, 0);
-}
FORCEINLINE
VOID
Modified: trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h [iso-8859-1] Thu Jan 21 23:34:01
2010
@@ -83,6 +83,7 @@
#include "../kdbg/kdb.h"
#endif
#include "dbgk.h"
+#include "spinlock.h"
#include "tag.h"
#include "test.h"
#include "inbv.h"
Modified: trunk/reactos/ntoskrnl/ke/spinlock.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/spinlock.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/spinlock.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/spinlock.c [iso-8859-1] Thu Jan 21 23:34:01 2010
@@ -456,15 +456,20 @@
}
#ifdef _M_IX86
-/*
- * @unimplemented
- */
-VOID
-NTAPI
-Kii386SpinOnSpinLock(IN PKSPIN_LOCK SpinLock,
- IN ULONG Flags)
-{
- UNIMPLEMENTED;
- while (TRUE);
-}
-#endif
+VOID
+NTAPI
+Kii386SpinOnSpinLock(PKSPIN_LOCK SpinLock, ULONG Flags)
+{
+ // FIXME: Handle flags
+ UNREFERENCED_PARAMETER(Flags);
+
+ /* Spin until it's unlocked */
+ while (*(volatile KSPIN_LOCK *)SpinLock & 1)
+ {
+ // FIXME: Check for timeout
+
+ /* Yield and keep looping */
+ YieldProcessor();
+ }
+}
+#endif