ReactOS 0.4.16-dev-106-g10b08aa
spinlock.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for spinlock.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define LQ_WAIT   1
 
#define LQ_OWN   2
 

Functions

 _IRQL_requires_min_ (DISPATCH_LEVEL)
 
KIRQL NTAPI KeAcquireInterruptSpinLock (IN PKINTERRUPT Interrupt)
 
VOID NTAPI KeReleaseInterruptSpinLock (IN PKINTERRUPT Interrupt, IN KIRQL OldIrql)
 
VOID NTAPI _KeInitializeSpinLock (IN PKSPIN_LOCK SpinLock)
 
VOID NTAPI KeAcquireSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock)
 
VOID NTAPI KeReleaseSpinLockFromDpcLevel (IN PKSPIN_LOCK SpinLock)
 
VOID FASTCALL KefAcquireSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock)
 
VOID FASTCALL KefReleaseSpinLockFromDpcLevel (IN PKSPIN_LOCK SpinLock)
 
VOID FASTCALL KiAcquireSpinLock (IN PKSPIN_LOCK SpinLock)
 
VOID FASTCALL KiReleaseSpinLock (IN PKSPIN_LOCK SpinLock)
 
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel (IN OUT PKSPIN_LOCK SpinLock)
 
VOID FASTCALL KeAcquireInStackQueuedSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
 
VOID FASTCALL KeReleaseInStackQueuedSpinLockFromDpcLevel (IN PKLOCK_QUEUE_HANDLE LockHandle)
 
KIRQL FASTCALL KeAcquireSpinLockForDpc (IN PKSPIN_LOCK SpinLock)
 
VOID FASTCALL KeReleaseSpinLockForDpc (IN PKSPIN_LOCK SpinLock, IN KIRQL OldIrql)
 
VOID FASTCALL KeAcquireInStackQueuedSpinLockForDpc (IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
 
VOID FASTCALL KeReleaseInStackQueuedSpinLockForDpc (IN PKLOCK_QUEUE_HANDLE LockHandle)
 
BOOLEAN FASTCALL KeTestSpinLock (IN PKSPIN_LOCK SpinLock)
 

Macro Definition Documentation

◆ LQ_OWN

#define LQ_OWN   2

Definition at line 16 of file spinlock.c.

◆ LQ_WAIT

#define LQ_WAIT   1

Definition at line 15 of file spinlock.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file spinlock.c.

Function Documentation

◆ _IRQL_requires_min_()

_IRQL_requires_min_ ( DISPATCH_LEVEL  )

Definition at line 97 of file spinlock.c.

103{
104#if defined(CONFIG_SMP) || DBG
105 /* Make sure we are at DPC or above! */
107 {
108 /* We aren't -- bugcheck */
109 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
110 (ULONG_PTR)LockHandle->Lock,
112 0,
113 0);
114 }
115#endif
116
117 /* Do the inlined function */
118 KxAcquireSpinLock(LockHandle->Lock);
119}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
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
uint32_t ULONG_PTR
Definition: typedefs.h:65
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:717

◆ _KeInitializeSpinLock()

VOID NTAPI _KeInitializeSpinLock ( IN PKSPIN_LOCK  SpinLock)

Definition at line 186 of file spinlock.c.

187{
188 /* Clear it */
189 *SpinLock = 0;
190}
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228

◆ KeAcquireInStackQueuedSpinLockAtDpcLevel()

VOID FASTCALL KeAcquireInStackQueuedSpinLockAtDpcLevel ( IN PKSPIN_LOCK  SpinLock,
IN PKLOCK_QUEUE_HANDLE  LockHandle 
)

Definition at line 363 of file spinlock.c.

365{
366 /* Set it up properly */
369#ifdef CONFIG_SMP
370#if 0
371 KeAcquireQueuedSpinLockAtDpcLevel(LockHandle->LockQueue.Next);
372#else
373 /* Make sure we are at DPC or above! */
375 {
376 /* We aren't -- bugcheck */
377 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
380 0,
381 0);
382 }
383#endif
384#endif
385
386 /* Acquire the lock */
387 KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
388}
#define NULL
Definition: types.h:112
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

Referenced by KeAcquireInStackQueuedSpinLockForDpc(), KiAcquireApcLockAtSynchLevel(), and KiAcquireDeviceQueueLock().

◆ KeAcquireInStackQueuedSpinLockForDpc()

VOID FASTCALL KeAcquireInStackQueuedSpinLockForDpc ( IN PKSPIN_LOCK  SpinLock,
IN PKLOCK_QUEUE_HANDLE  LockHandle 
)

Definition at line 446 of file spinlock.c.

448{
452 else
454}
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130
VOID FASTCALL KeAcquireInStackQueuedSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:363

◆ KeAcquireInterruptSpinLock()

KIRQL NTAPI KeAcquireInterruptSpinLock ( IN PKINTERRUPT  Interrupt)

Definition at line 154 of file spinlock.c.

155{
157
158 /* Raise IRQL */
159 KeRaiseIrql(Interrupt->SynchronizeIrql, &OldIrql);
160
161 /* Acquire spinlock on MP */
163 return OldIrql;
164}
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFINTERRUPT * Interrupt
Definition: wdfinterrupt.h:379
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by i8042DpcRoutineMouseTimeout(), i8042KbdDpcRoutine(), i8042MouDpcRoutine(), i8042PacketDpc(), i8042StartPacket(), InPortDpcForIsr(), Mx::MxAcquireInterruptSpinLock(), PortAcquireSpinLock(), and StartProcedure().

◆ KeAcquireSpinLockAtDpcLevel()

VOID NTAPI KeAcquireSpinLockAtDpcLevel ( IN PKSPIN_LOCK  SpinLock)

Definition at line 198 of file spinlock.c.

199{
200 /* Make sure we are at DPC or above! */
202 {
203 /* We aren't -- bugcheck */
204 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
207 0,
208 0);
209 }
210
211 /* Do the inlined function */
212 KxAcquireSpinLock(SpinLock);
213}

◆ KeAcquireSpinLockForDpc()

KIRQL FASTCALL KeAcquireSpinLockForDpc ( IN PKSPIN_LOCK  SpinLock)

Definition at line 424 of file spinlock.c.

425{
427 return 0;
428}
#define UNIMPLEMENTED
Definition: debug.h:118

◆ KefAcquireSpinLockAtDpcLevel()

VOID FASTCALL KefAcquireSpinLockAtDpcLevel ( IN PKSPIN_LOCK  SpinLock)

Definition at line 243 of file spinlock.c.

244{
245 /* Make sure we are at DPC or above! */
247 {
248 /* We aren't -- bugcheck */
249 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
252 0,
253 0);
254 }
255
256 /* Do the inlined function */
257 KxAcquireSpinLock(SpinLock);
258}

◆ KefReleaseSpinLockFromDpcLevel()

VOID FASTCALL KefReleaseSpinLockFromDpcLevel ( IN PKSPIN_LOCK  SpinLock)

Definition at line 265 of file spinlock.c.

266{
267 /* Make sure we are at DPC or above! */
269 {
270 /* We aren't -- bugcheck */
271 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
274 0,
275 0);
276 }
277
278 /* Do the inlined function */
279 KxReleaseSpinLock(SpinLock);
280}

◆ KeReleaseInStackQueuedSpinLockForDpc()

VOID FASTCALL KeReleaseInStackQueuedSpinLockForDpc ( IN PKLOCK_QUEUE_HANDLE  LockHandle)

Definition at line 461 of file spinlock.c.

462{
465 else
467
468}
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
VOID FASTCALL KeReleaseInStackQueuedSpinLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:395

◆ KeReleaseInStackQueuedSpinLockFromDpcLevel()

VOID FASTCALL KeReleaseInStackQueuedSpinLockFromDpcLevel ( IN PKLOCK_QUEUE_HANDLE  LockHandle)

Definition at line 395 of file spinlock.c.

396{
397#ifdef CONFIG_SMP
398#if 0
399 /* Call the internal function */
400 KeReleaseQueuedSpinLockFromDpcLevel(LockHandle->LockQueue.Next);
401#else
402 /* Make sure we are at DPC or above! */
404 {
405 /* We aren't -- bugcheck */
406 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
409 0,
410 0);
411 }
412#endif
413#endif
414
415 /* Release the lock */
416 KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
417}

Referenced by KeReleaseInStackQueuedSpinLockForDpc(), KiReleaseApcLockFromSynchLevel(), KiReleaseDeviceQueueLock(), and KiReleaseProcessLockFromSynchLevel().

◆ KeReleaseInterruptSpinLock()

VOID NTAPI KeReleaseInterruptSpinLock ( IN PKINTERRUPT  Interrupt,
IN KIRQL  OldIrql 
)

Definition at line 171 of file spinlock.c.

173{
174 /* Release lock on MP */
176
177 /* Lower IRQL */
179}
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135

Referenced by i8042DpcRoutineMouseTimeout(), i8042KbdDpcRoutine(), i8042MouDpcRoutine(), i8042PacketDpc(), i8042StartPacket(), InPortDpcForIsr(), Mx::MxReleaseInterruptSpinLock(), PortReleaseSpinLock(), and StartProcedure().

◆ KeReleaseSpinLockForDpc()

VOID FASTCALL KeReleaseSpinLockForDpc ( IN PKSPIN_LOCK  SpinLock,
IN KIRQL  OldIrql 
)

Definition at line 435 of file spinlock.c.

437{
439}

◆ KeReleaseSpinLockFromDpcLevel()

VOID NTAPI KeReleaseSpinLockFromDpcLevel ( IN PKSPIN_LOCK  SpinLock)

Definition at line 221 of file spinlock.c.

222{
223 /* Make sure we are at DPC or above! */
225 {
226 /* We aren't -- bugcheck */
227 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
230 0,
231 0);
232 }
233
234 /* Do the inlined function */
235 KxReleaseSpinLock(SpinLock);
236}

◆ KeTestSpinLock()

BOOLEAN FASTCALL KeTestSpinLock ( IN PKSPIN_LOCK  SpinLock)

Definition at line 475 of file spinlock.c.

476{
477 /* Test this spinlock */
478 if (*SpinLock)
479 {
480 /* Spinlock is busy, yield execution */
482
483 /* Return busy flag */
484 return FALSE;
485 }
486
487 /* Spinlock appears to be free */
488 return TRUE;
489}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define YieldProcessor
Definition: ke.h:48

Referenced by InbvAcquireLock(), IntVideoPortResetDisplayParametersEx(), KdbpAcquireLock(), and KdpAcquireLock().

◆ KeTryToAcquireSpinLockAtDpcLevel()

BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel ( IN OUT PKSPIN_LOCK  SpinLock)

Definition at line 309 of file spinlock.c.

310{
311#if DBG
312 /* Make sure we are at DPC or above! */
314 {
315 /* We aren't -- bugcheck */
316 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
319 0,
320 0);
321 }
322
323 /* Make sure that we don't own the lock already */
324 if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock)
325 {
326 /* We do, bugcheck! */
327 KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
328 }
329#endif
330
331#ifdef CONFIG_SMP
332 /* Check if it's already acquired */
333 if (!(*SpinLock))
334 {
335 /* Try to acquire it */
337 {
338 /* Someone else acquired it */
339 return FALSE;
340 }
341 }
342 else
343 {
344 /* It was already acquired */
345 return FALSE;
346 }
347#endif
348
349#if DBG
350 /* On debug builds, we OR in the KTHREAD */
352#endif
353
354 /* All is well, return TRUE */
355 return TRUE;
356}
#define ULONG_PTR
Definition: config.h:101
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define KeGetCurrentThread
Definition: hal.h:55
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
int32_t * PLONG
Definition: typedefs.h:58

Referenced by KdbpAcquireLock(), KdEnterDebugger(), KdpAcquireLock(), KdPollBreakIn(), KeTryToAcquireQueuedSpinLock(), and KeTryToAcquireQueuedSpinLockRaiseToSynch().

◆ KiAcquireSpinLock()

VOID FASTCALL KiAcquireSpinLock ( IN PKSPIN_LOCK  SpinLock)

Definition at line 287 of file spinlock.c.

288{
289 /* Do the inlined function */
290 KxAcquireSpinLock(SpinLock);
291}

Referenced by InbvAcquireLock(), KdpPortLock(), KeInsertQueueDpc(), and KeRemoveQueueDpc().

◆ KiReleaseSpinLock()

VOID FASTCALL KiReleaseSpinLock ( IN PKSPIN_LOCK  SpinLock)

Definition at line 298 of file spinlock.c.

299{
300 /* Do the inlined function */
301 KxReleaseSpinLock(SpinLock);
302}

Referenced by InbvReleaseLock(), KdbpReleaseLock(), KdpPortUnlock(), KdpReleaseLock(), KeInsertQueueDpc(), and KeRemoveQueueDpc().