Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenspinlock.h
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/include/spinlock.h 00005 * PURPOSE: Internal Inlined Functions for spinlocks, shared with HAL 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 */ 00008 00009 VOID 00010 NTAPI 00011 Kii386SpinOnSpinLock(PKSPIN_LOCK SpinLock, ULONG Flags); 00012 00013 #ifndef CONFIG_SMP 00014 00015 // 00016 // Spinlock Acquire at IRQL >= DISPATCH_LEVEL 00017 // 00018 FORCEINLINE 00019 VOID 00020 KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock) 00021 { 00022 /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */ 00023 UNREFERENCED_PARAMETER(SpinLock); 00024 00025 /* Add an explicit memory barrier to prevent the compiler from reordering 00026 memory accesses across the borders of spinlocks */ 00027 KeMemoryBarrierWithoutFence(); 00028 } 00029 00030 // 00031 // Spinlock Release at IRQL >= DISPATCH_LEVEL 00032 // 00033 FORCEINLINE 00034 VOID 00035 KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock) 00036 { 00037 /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */ 00038 UNREFERENCED_PARAMETER(SpinLock); 00039 00040 /* Add an explicit memory barrier to prevent the compiler from reordering 00041 memory accesses across the borders of spinlocks */ 00042 KeMemoryBarrierWithoutFence(); 00043 } 00044 00045 #else 00046 00047 // 00048 // Spinlock Acquisition at IRQL >= DISPATCH_LEVEL 00049 // 00050 FORCEINLINE 00051 VOID 00052 KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock) 00053 { 00054 #if DBG 00055 /* Make sure that we don't own the lock already */ 00056 if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock) 00057 { 00058 /* We do, bugcheck! */ 00059 KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0); 00060 } 00061 #endif 00062 00063 /* Try to acquire the lock */ 00064 while (InterlockedBitTestAndSet((PLONG)SpinLock, 0)) 00065 { 00066 #if defined(_M_IX86) && DBG 00067 /* On x86 debug builds, we use a much slower but useful routine */ 00068 Kii386SpinOnSpinLock(SpinLock, 5); 00069 #else 00070 /* It's locked... spin until it's unlocked */ 00071 while (*(volatile KSPIN_LOCK *)SpinLock & 1) 00072 { 00073 /* Yield and keep looping */ 00074 YieldProcessor(); 00075 } 00076 #endif 00077 } 00078 #if DBG 00079 /* On debug builds, we OR in the KTHREAD */ 00080 *SpinLock = (KSPIN_LOCK)KeGetCurrentThread() | 1; 00081 #endif 00082 } 00083 00084 // 00085 // Spinlock Release at IRQL >= DISPATCH_LEVEL 00086 // 00087 FORCEINLINE 00088 VOID 00089 KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock) 00090 { 00091 #if DBG 00092 /* Make sure that the threads match */ 00093 if (((KSPIN_LOCK)KeGetCurrentThread() | 1) != *SpinLock) 00094 { 00095 /* They don't, bugcheck */ 00096 KeBugCheckEx(SPIN_LOCK_NOT_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0); 00097 } 00098 #endif 00099 /* Clear the lock */ 00100 InterlockedAnd((PLONG)SpinLock, 0); 00101 } 00102 00103 #endif Generated on Mon May 28 2012 04:37:10 for ReactOS by
1.7.6.1
|