ReactOS 0.4.15-dev-8076-g06e89b2
spinlock.h
Go to the documentation of this file.
1/*
2* PROJECT: ReactOS Kernel
3* LICENSE: GPL - See COPYING in the top level directory
4* FILE: ntoskrnl/include/internal/spinlock.h
5* PURPOSE: Internal Inlined Functions for spinlocks, shared with HAL
6* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7*/
8
9#if defined(_M_IX86)
10VOID
12Kii386SpinOnSpinLock(PKSPIN_LOCK SpinLock, ULONG Flags);
13#endif
14
15//
16// Spinlock Acquisition at IRQL >= DISPATCH_LEVEL
17//
20VOID
21KxAcquireSpinLock(
22#if defined(CONFIG_SMP) || DBG
24#else
26#endif
28{
29#if DBG
30 /* Make sure that we don't own the lock already */
31 if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock)
32 {
33 /* We do, bugcheck! */
34 KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
35 }
36#endif
37
38#ifdef CONFIG_SMP
39 /* Try to acquire the lock */
41 {
42#if defined(_M_IX86) && DBG
43 /* On x86 debug builds, we use a much slower but useful routine */
44 Kii386SpinOnSpinLock(SpinLock, 5);
45#else
46 /* It's locked... spin until it's unlocked */
47 while (*(volatile KSPIN_LOCK *)SpinLock & 1)
48 {
49 /* Yield and keep looping */
51 }
52#endif
53 }
54#endif
55
56 /* Add an explicit memory barrier to prevent the compiler from reordering
57 memory accesses across the borders of spinlocks */
59
60#if DBG
61 /* On debug builds, we OR in the KTHREAD */
63#endif
64}
65
66//
67// Spinlock Release at IRQL >= DISPATCH_LEVEL
68//
71VOID
72KxReleaseSpinLock(
73#if defined(CONFIG_SMP) || DBG
75#else
77#endif
79{
80#if DBG
81 /* Make sure that the threads match */
82 if (((KSPIN_LOCK)KeGetCurrentThread() | 1) != *SpinLock)
83 {
84 /* They don't, bugcheck */
85 KeBugCheckEx(SPIN_LOCK_NOT_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
86 }
87#endif
88
89#if defined(CONFIG_SMP) || DBG
90 /* Clear the lock */
91#ifdef _WIN64
93#else
95#endif
96#endif
97
98 /* Add an explicit memory barrier to prevent the compiler from reordering
99 memory accesses across the borders of spinlocks */
101}
__int64 * PLONG64
Definition: basetsd.h:183
#define _Acquires_nonreentrant_lock_(lock)
#define _Releases_nonreentrant_lock_(lock)
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define KeGetCurrentThread
Definition: hal.h:55
#define InterlockedAnd64
Definition: interlocked.h:87
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define InterlockedAnd
Definition: interlocked.h:62
#define DBG(x)
Definition: moztest.c:12
#define _Inout_
Definition: ms_sal.h:378
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
#define KeMemoryBarrierWithoutFence()
Definition: ke.h:66
#define YieldProcessor
Definition: ke.h:48
#define _Unreferenced_parameter_
Definition: specstrings.h:396
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
#define FORCEINLINE
Definition: wdftypes.h:67
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170