ReactOS  0.4.13-dev-39-g8b6696f
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  */
23 KIRQL
25 {
26  KIRQL OldIrql;
27 
28  /* Raise to sync */
30 
31  /* Acquire the lock and return */
33  return OldIrql;
34 }
35 
36 /*
37  * @implemented
38  */
39 KIRQL
40 NTAPI
42 {
43  KIRQL OldIrql;
44 
45  /* Raise to dispatch */
47 
48  /* Acquire the lock and return */
50  return OldIrql;
51 }
52 
53 /*
54  * @implemented
55  */
56 VOID
57 NTAPI
59  KIRQL OldIrql)
60 {
61  /* Release the lock and lower IRQL back */
64 }
65 
66 /*
67  * @implemented
68  */
69 KIRQL
71 {
72  KIRQL OldIrql;
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  */
85 KIRQL
87 {
88  KIRQL OldIrql;
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  */
101 VOID
104 {
105  /* Set up the lock */
108 
109  /* Raise to dispatch */
111 
112  /* Acquire the lock */
114 }
115 
116 
117 /*
118  * @implemented
119  */
120 VOID
123 {
124  /* Set up the lock */
127 
128  /* Raise to synch */
130 
131  /* Acquire the lock */
133 }
134 
135 
136 /*
137  * @implemented
138  */
139 VOID
141  IN KIRQL OldIrql)
142 {
143  /* Release the lock */
144  KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
145 
146  /* Lower IRQL back */
148 }
149 
150 
151 /*
152  * @implemented
153  */
154 VOID
156 {
157  /* Simply lower IRQL back */
160 }
161 
162 
163 /*
164  * @implemented
165  */
166 BOOLEAN
168  IN PKIRQL OldIrql)
169 {
170 #ifndef CONFIG_SMP
171  /* Simply raise to dispatch */
173 
174  /* Add an explicit memory barrier to prevent the compiler from reordering
175  memory accesses across the borders of spinlocks */
177 
178  /* Always return true on UP Machines */
179  return TRUE;
180 #else
182  ASSERT(FALSE);
183 #endif
184 }
185 
186 /*
187  * @implemented
188  */
189 LOGICAL
192 {
193 #ifndef CONFIG_SMP
194  /* Simply raise to dispatch */
196 
197  /* Add an explicit memory barrier to prevent the compiler from reordering
198  memory accesses across the borders of spinlocks */
200 
201  /* Always return true on UP Machines */
202  return TRUE;
203 #else
205  ASSERT(FALSE);
206 #endif
207 }
208 
209 /* EOF */
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:38
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:1062
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
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define KeMemoryBarrierWithoutFence()
Definition: ke.h:66
LOGICAL FASTCALL KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, OUT PKIRQL OldIrql)
Definition: spinlock.c:192
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.h:20
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
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
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
VOID NTAPI KeReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL NewIrql)
Definition: spinlock.c:73
KIRQL FASTCALL KeAcquireSpinLockRaiseToSynch(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:62
KIRQL NTAPI KeAcquireSpinLockRaiseToDpc(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:41
#define OUT
Definition: typedefs.h:39
#define UNIMPLEMENTED
Definition: debug.h:114
KSPIN_LOCK_QUEUE LockQueue
Definition: ketypes.h:615
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:742
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
KIRQL FASTCALL KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:119