ReactOS 0.4.15-dev-8093-g3285f69
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: ntoskrnl/ke/amd64/spinlock.c
5 * PURPOSE: Spinlock and Queued Spinlock Support
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ntoskrnl.h>
12#define NDEBUG
13#include <debug.h>
14
15#undef KeAcquireSpinLock
16#undef KeReleaseSpinLock
17
18/* FUNCTIONS *****************************************************************/
19
20/*
21 * @implemented
22 */
25{
27
28 /* Raise to sync */
30
31 /* Acquire the lock and return */
32 KxAcquireSpinLock(SpinLock);
33 return OldIrql;
34}
35
36/*
37 * @implemented
38 */
42{
44
45 /* Raise to dispatch */
47
48 /* Acquire the lock and return */
49 KxAcquireSpinLock(SpinLock);
50 return OldIrql;
51}
52
53/*
54 * @implemented
55 */
56VOID
60{
61 /* Release the lock and lower IRQL back */
62 KxReleaseSpinLock(SpinLock);
64}
65
66/*
67 * @implemented
68 */
71{
73
74 /* Raise to dispatch */
76
77 /* Acquire the lock */
78 KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
79 return OldIrql;
80}
81
82/*
83 * @implemented
84 */
87{
89
90 /* Raise to synch */
92
93 /* Acquire the lock */
94 KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
95 return OldIrql;
96}
97
98/*
99 * @implemented
100 */
101VOID
104{
105 /* Set up the lock */
108
109 /* Raise to dispatch */
111
112 /* Acquire the lock */
113 KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
114}
115
116
117/*
118 * @implemented
119 */
120VOID
123{
124 /* Set up the lock */
127
128 /* Raise to synch */
130
131 /* Acquire the lock */
132 KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
133}
134
135
136/*
137 * @implemented
138 */
139VOID
142{
143 /* Release the lock */
144 KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
145
146 /* Lower IRQL back */
148}
149
150
151/*
152 * @implemented
153 */
154VOID
156{
157 /* Simply lower IRQL back */
158 KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
160}
161
162
163/*
164 * @implemented
165 */
169{
170 /* Raise to synch level */
172
173#ifdef CONFIG_SMP
174 // HACK
175 return KeTryToAcquireSpinLockAtDpcLevel(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock);
176#else
177 /* Add an explicit memory barrier to prevent the compiler from reordering
178 memory accesses across the borders of spinlocks */
180
181 /* Always return true on UP Machines */
182 return TRUE;
183#endif
184}
185
186/*
187 * @implemented
188 */
189LOGICAL
192{
193 /* Raise to dispatch level */
195
196#ifdef CONFIG_SMP
197 // HACK
198 return KeTryToAcquireSpinLockAtDpcLevel(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock);
199#else
200
201 /* Add an explicit memory barrier to prevent the compiler from reordering
202 memory accesses across the borders of spinlocks */
204
205 /* Always return true on UP Machines */
206 return TRUE;
207#endif
208}
209
210/* EOF */
unsigned char BOOLEAN
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#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
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
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
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
KIRQL NTAPI KeAcquireSpinLockRaiseToDpc(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:41
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
Definition: spinlock.c:309
#define KeMemoryBarrierWithoutFence()
Definition: ke.h:66
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
#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
_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