ReactOS  0.4.15-dev-448-gd6c4411
spinlock.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS HAL
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: hal/halx86/generic/spinlock.c
5  * PURPOSE: Spinlock and Queued Spinlock Support
6  * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 /* This file is compiled twice. Once for UP and once for MP */
12 
13 #include <hal.h>
14 #define NDEBUG
15 #include <debug.h>
16 
17 #include <internal/spinlock.h>
18 
19 #undef KeAcquireSpinLock
20 #undef KeReleaseSpinLock
21 
22 /* GLOBALS *******************************************************************/
23 
26 
27 /* FUNCTIONS *****************************************************************/
28 
29 #ifdef _M_IX86
30 
31 /*
32  * @implemented
33  */
34 KIRQL
37 {
38  KIRQL OldIrql;
39 
40  /* Raise to sync */
42 
43  /* Acquire the lock and return */
45  return OldIrql;
46 }
47 
48 /*
49  * @implemented
50  */
51 KIRQL
54 {
55  KIRQL OldIrql;
56 
57  /* Raise to dispatch and acquire the lock */
60  return OldIrql;
61 }
62 
63 /*
64  * @implemented
65  */
66 VOID
69  KIRQL OldIrql)
70 {
71  /* Release the lock and lower IRQL back */
74 }
75 
76 /*
77  * @implemented
78  */
79 KIRQL
82 {
83  KIRQL OldIrql;
84 
85  /* Raise to dispatch */
87 
88  /* Acquire the lock */
89  KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
90  return OldIrql;
91 }
92 
93 /*
94  * @implemented
95  */
96 KIRQL
99 {
100  KIRQL OldIrql;
101 
102  /* Raise to synch */
104 
105  /* Acquire the lock */
106  KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
107  return OldIrql;
108 }
109 
110 /*
111  * @implemented
112  */
113 VOID
114 FASTCALL
117 {
118  /* Set up the lock */
121 
122  /* Raise to dispatch */
124 
125  /* Acquire the lock */
127 }
128 
129 /*
130  * @implemented
131  */
132 VOID
133 FASTCALL
136 {
137  /* Set up the lock */
140 
141  /* Raise to synch */
143 
144  /* Acquire the lock */
146 }
147 
148 /*
149  * @implemented
150  */
151 VOID
152 FASTCALL
154  IN KIRQL OldIrql)
155 {
156  /* Release the lock */
157  KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
158 
159  /* Lower IRQL back */
161 }
162 
163 /*
164  * @implemented
165  */
166 VOID
167 FASTCALL
169 {
170  /* Simply lower IRQL back */
173 }
174 
175 /*
176  * @implemented
177  */
178 BOOLEAN
179 FASTCALL
181  IN PKIRQL OldIrql)
182 {
183 #ifdef CONFIG_SMP
184  ERROR_DBGBREAK("FIXME: Unused\n"); // FIXME: Unused
185  return FALSE;
186 #endif
187 
188  /* Simply raise to synch */
190 
191  /* Add an explicit memory barrier to prevent the compiler from reordering
192  memory accesses across the borders of spinlocks */
194 
195  /* Always return true on UP Machines */
196  return TRUE;
197 }
198 
199 /*
200  * @implemented
201  */
202 LOGICAL
203 FASTCALL
206 {
207 #ifdef CONFIG_SMP
208  ERROR_DBGBREAK("FIXME: Unused\n"); // FIXME: Unused
209  return FALSE;
210 #endif
211 
212  /* Simply raise to dispatch */
214 
215  /* Add an explicit memory barrier to prevent the compiler from reordering
216  memory accesses across the borders of spinlocks */
218 
219  /* Always return true on UP Machines */
220  return TRUE;
221 }
222 
223 #endif
224 
225 VOID
226 NTAPI
228 {
230 
231  /* Get flags and disable interrupts */
232  Flags = __readeflags();
233  _disable();
234 
235  /* Acquire the lock */
237 
238  /* We have the lock, save the flags now */
240 }
241 
242 VOID
243 NTAPI
245 {
247 
248  /* Get the flags */
250 
251  /* Release the lock */
253 
254  /* Restore the flags */
256 }
257 
BOOLEAN FASTCALL KeTryToAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN PKIRQL OldIrql)
Definition: spinlock.c:177
VOID FASTCALL KeAcquireInStackQueuedSpinLockRaiseToSynch(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:142
#define IN
Definition: typedefs.h:39
PKSPIN_LOCK volatile Lock
Definition: ketypes.h:611
#define TRUE
Definition: types.h:120
FORCEINLINE VOID KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.h:35
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1063
struct _KSPIN_LOCK_QUEUE *volatile Next
Definition: ketypes.h:610
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130
#define FASTCALL
Definition: nt_native.h:50
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
uint32_t ULONG_PTR
Definition: typedefs.h:64
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define KeMemoryBarrierWithoutFence()
Definition: ke.h:66
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
LOGICAL FASTCALL KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, OUT PKIRQL OldIrql)
Definition: spinlock.c:192
#define ERROR_DBGBREAK(...)
Definition: debug.h:221
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.h:20
ULONG_PTR HalpSystemHardwareFlags
Definition: spinlock.c:24
KSPIN_LOCK HalpSystemHardwareLock
Definition: spinlock.c:25
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
enum _KSPIN_LOCK_QUEUE_NUMBER KSPIN_LOCK_QUEUE_NUMBER
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
KIRQL FASTCALL KeAcquireSpinLockRaiseToSynch(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:62
#define OUT
Definition: typedefs.h:40
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
void __cdecl _disable(void)
Definition: intrin_arm.h:365
KSPIN_LOCK_QUEUE LockQueue
Definition: ketypes.h:615
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:729
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
KIRQL FASTCALL KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:119