ReactOS 0.4.16-dev-122-g325d74c
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#ifdef _MINIHAL_
32VOID
36{
37#if DBG
38 /* To be on par with HAL/NTOSKRNL */
40#endif
41}
42#endif /* defined(_MINIHAL_) */
43
44/*
45 * @implemented
46 */
50{
52
53 /* Raise to sync */
55
56 /* Acquire the lock and return */
57 KxAcquireSpinLock(SpinLock);
58 return OldIrql;
59}
60
61/*
62 * @implemented
63 */
67{
69
70 /* Raise to dispatch and acquire the lock */
72 KxAcquireSpinLock(SpinLock);
73 return OldIrql;
74}
75
76/*
77 * @implemented
78 */
79VOID
83{
84 /* Release the lock and lower IRQL back */
85 KxReleaseSpinLock(SpinLock);
87}
88
89/*
90 * @implemented
91 */
95{
97
98 /* Raise to dispatch */
100
101 /* Acquire the lock */
102 KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
103 return OldIrql;
104}
105
106/*
107 * @implemented
108 */
109KIRQL
112{
114
115 /* Raise to synch */
117
118 /* Acquire the lock */
119 KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
120 return OldIrql;
121}
122
123/*
124 * @implemented
125 */
126VOID
130{
131 /* Set up the lock */
134
135 /* Raise to dispatch */
137
138 /* Acquire the lock */
139 KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
140}
141
142/*
143 * @implemented
144 */
145VOID
149{
150 /* Set up the lock */
153
154 /* Raise to synch */
156
157 /* Acquire the lock */
158 KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
159}
160
161/*
162 * @implemented
163 */
164VOID
168{
169 /* Release the lock */
170 KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
171
172 /* Lower IRQL back */
174}
175
176/*
177 * @implemented
178 */
179VOID
182{
183 /* Simply lower IRQL back */
184 KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
186}
187
188#ifndef _MINIHAL_
189/*
190 * @implemented
191 */
196{
197 PKSPIN_LOCK Lock = KeGetCurrentPrcb()->LockQueue[LockNumber].Lock;
198
199 /* KM tests demonstrate that this raises IRQL even if locking fails */
201 /* HACK */
203}
204
205/*
206 * @implemented
207 */
208LOGICAL
212{
213 PKSPIN_LOCK Lock = KeGetCurrentPrcb()->LockQueue[LockNumber].Lock;
214
215 /* KM tests demonstrate that this raises IRQL even if locking fails */
217 /* HACK */
219}
220#endif /* !defined(_MINIHAL_) */
221
222#endif /* defined(_M_IX86) */
223
224VOID
225NTAPI
227{
229
230 /* Get flags and disable interrupts */
232 _disable();
233
234 /* Acquire the lock */
235 KxAcquireSpinLock(&HalpSystemHardwareLock);
236
237 /* We have the lock, save the flags now */
239}
240
241VOID
242NTAPI
244{
246
247 /* Get the flags */
249
250 /* Release the lock */
251 KxReleaseSpinLock(&HalpSystemHardwareLock);
252
253 /* Restore the flags */
255}
256
unsigned char BOOLEAN
#define NULL
Definition: types.h:112
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
KIRQL FASTCALL KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:119
VOID FASTCALL KeAcquireInStackQueuedSpinLockRaiseToSynch(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:142
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
BOOLEAN FASTCALL KeTryToAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN PKIRQL OldIrql)
Definition: spinlock.c:177
KIRQL FASTCALL KeAcquireSpinLockRaiseToSynch(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:62
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
LOGICAL FASTCALL KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, OUT PKIRQL OldIrql)
Definition: spinlock.c:192
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
KSPIN_LOCK HalpSystemHardwareLock
Definition: spinlock.c:25
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:243
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:226
ULONG_PTR HalpSystemHardwareFlags
Definition: spinlock.c:24
#define KeGetCurrentThread
Definition: hal.h:55
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
#define FASTCALL
Definition: nt_native.h:50
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
Definition: spinlock.c:309
VOID FASTCALL KefAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:243
KSPIN_LOCK_QUEUE LockQueue
Definition: ketypes.h:627
struct _KSPIN_LOCK_QUEUE *volatile Next
Definition: ketypes.h:622
PKSPIN_LOCK volatile Lock
Definition: ketypes.h:623
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:717
enum _KSPIN_LOCK_QUEUE_NUMBER KSPIN_LOCK_QUEUE_NUMBER