ReactOS  0.4.15-dev-3440-g915569a
spinlock.h
Go to the documentation of this file.
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/internal/spinlock.h
5 * PURPOSE: Internal Inlined Functions for spinlocks, shared with HAL
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8 
9 #if defined(_M_IX86)
10 VOID
11 NTAPI
12 Kii386SpinOnSpinLock(PKSPIN_LOCK SpinLock, ULONG Flags);
13 #endif
14 
15 //
16 // Spinlock Acquisition at IRQL >= DISPATCH_LEVEL
17 //
20 VOID
21 KxAcquireSpinLock(
22 #if defined(CONFIG_SMP) || DBG
23  _Inout_
24 #else
26 #endif
28 {
29 #if DBG
30  /* Make sure that we don't own the lock already */
31  if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock)
32  {
33  /* We do, bugcheck! */
34  KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
35  }
36 #endif
37 
38 #ifdef CONFIG_SMP
39  /* Try to acquire the lock */
41  {
42 #if defined(_M_IX86) && DBG
43  /* On x86 debug builds, we use a much slower but useful routine */
44  Kii386SpinOnSpinLock(SpinLock, 5);
45 #else
46  /* It's locked... spin until it's unlocked */
47  while (*(volatile KSPIN_LOCK *)SpinLock & 1)
48  {
49  /* Yield and keep looping */
51  }
52 #endif
53  }
54 #endif
55 
56  /* Add an explicit memory barrier to prevent the compiler from reordering
57  memory accesses across the borders of spinlocks */
59 
60 #if DBG
61  /* On debug builds, we OR in the KTHREAD */
63 #endif
64 }
65 
66 //
67 // Spinlock Release at IRQL >= DISPATCH_LEVEL
68 //
71 VOID
72 KxReleaseSpinLock(
73 #if defined(CONFIG_SMP) || DBG
74  _Inout_
75 #else
77 #endif
79 {
80 #if DBG
81  /* Make sure that the threads match */
82  if (((KSPIN_LOCK)KeGetCurrentThread() | 1) != *SpinLock)
83  {
84  /* They don't, bugcheck */
85  KeBugCheckEx(SPIN_LOCK_NOT_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
86  }
87 #endif
88 
89 #if defined(CONFIG_SMP) || DBG
90  /* Clear the lock */
91 #ifdef _WIN64
93 #else
95 #endif
96 #endif
97 
98  /* Add an explicit memory barrier to prevent the compiler from reordering
99  memory accesses across the borders of spinlocks */
101 }
#define InterlockedAnd64
Definition: interlocked.h:87
#define InterlockedAnd
Definition: interlocked.h:62
#define _Inout_
Definition: ms_sal.h:378
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
uint32_t ULONG_PTR
Definition: typedefs.h:65
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
#define _Unreferenced_parameter_
Definition: specstrings.h:396
_Acquires_nonreentrant_lock_(SpinLock) FORCEINLINE VOID KxAcquireSpinLock(_Unreferenced_parameter_ PKSPIN_LOCK SpinLock)
Definition: spinlock.h:18
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_Releases_nonreentrant_lock_(SpinLock) FORCEINLINE VOID KxReleaseSpinLock(_Unreferenced_parameter_ PKSPIN_LOCK SpinLock)
Definition: spinlock.h:69
#define KeMemoryBarrierWithoutFence()
Definition: ke.h:66
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
#define DBG(x)
Definition: moztest.c:12
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define FORCEINLINE
Definition: wdftypes.h:67
unsigned int ULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:55
signed int * PLONG
Definition: retypes.h:5
__int64 * PLONG64
Definition: basetsd.h:185
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108