Author: tkreuzer
Date: Sat Jan 2 17:22:43 2010
New Revision: 44886
URL:
http://svn.reactos.org/svn/reactos?rev=44886&view=rev
Log:
[KE]
- 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
Modified:
branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/ke_x.h
branches/ros-amd64-bringup/reactos/ntoskrnl/ke/i386/trap.s
branches/ros-amd64-bringup/reactos/ntoskrnl/ke/spinlock.c
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/ke_x.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/ke_x.h [iso-8859-1]
(original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/ke_x.h [iso-8859-1] Sat
Jan 2 17:22:43 2010
@@ -101,6 +101,10 @@
} \
}
+VOID
+NTAPI
+Kii386SpinOnSpinLock(PKSPIN_LOCK SpinLock, ULONG Flags);
+
#ifndef CONFIG_SMP
//
// Spinlock Acquire at IRQL >= DISPATCH_LEVEL
@@ -310,44 +314,34 @@
VOID
KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
{
+#ifdef DBG
/* 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 */
+#endif
+
+ /* Try to acquire the lock */
+ while (InterlockedBitTestAndSet((PLONG)SpinLock, 0))
+ {
+#if defined(_M_IX86) && defined(DBG)
+ /* On x86 debug builds, we use a much slower but useful routine */
+ Kii386SpinOnSpinLock(SpinLock, 5);
+#else
+ /* It's locked... spin until it's unlocked */
+ while (*(volatile KSPIN_LOCK *)SpinLock & 1)
+ {
+ /* Yield and keep looping */
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;
+ }
+#ifdef DBG
+ /* On debug builds, we OR in the KTHREAD */
+ *SpinLock = (KSPIN_LOCK)KeGetCurrentThread() | 1;
#endif
- /* All is well, break out */
- break;
- }
- }
}
//
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/i386/trap.s
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/i386/trap.s [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/i386/trap.s [iso-8859-1] Sat Jan 2
17:22:43 2010
@@ -2828,31 +2828,3 @@
ret 12
.endfunc
-/*++
- * Kii386SpinOnSpinLock
- *
- * FILLMEIN
- *
- * Params:
- * SpinLock - FILLMEIN
- *
- * Flags - FILLMEIN
- *
- * Returns:
- * None.
- *
- * Remarks:
- * FILLMEIN
- *
- *--*/
-.globl _Kii386SpinOnSpinLock@8
-.func Kii386SpinOnSpinLock@8
-_Kii386SpinOnSpinLock@8:
-
-#ifdef CONFIG_SMP
- /* FIXME: TODO */
- int 3
-#endif
-
- ret 8
-.endfunc
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/spinlock.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/spinlock.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/spinlock.c [iso-8859-1] Sat Jan 2
17:22:43 2010
@@ -454,3 +454,22 @@
/* Spinlock appears to be free */
return TRUE;
}
+
+#ifdef _M_IX86
+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