ReactOS 0.4.16-dev-257-g6aa11ac
interlocked.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for interlocked.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

FORCEINLINE BOOLEAN _ExiDisableInterruptsAndAcquireSpinlock (IN OUT PKSPIN_LOCK Lock)
 
FORCEINLINE VOID _ExiReleaseSpinLockAndRestoreInterrupts (IN OUT PKSPIN_LOCK Lock, BOOLEAN Enable)
 
LARGE_INTEGER NTAPI ExInterlockedAddLargeInteger (IN OUT PLARGE_INTEGER Addend, IN LARGE_INTEGER Increment, IN OUT PKSPIN_LOCK Lock)
 
ULONG NTAPI ExInterlockedAddUlong (IN OUT PULONG Addend, IN ULONG Increment, IN OUT PKSPIN_LOCK Lock)
 
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList (IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
 
PLIST_ENTRY NTAPI ExInterlockedInsertTailList (IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
 
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList (IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
 
PSINGLE_LIST_ENTRY NTAPI ExInterlockedPopEntryList (IN OUT PSINGLE_LIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
 
PSINGLE_LIST_ENTRY NTAPI ExInterlockedPushEntryList (IN OUT PSINGLE_LIST_ENTRY ListHead, IN OUT PSINGLE_LIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
 
INTERLOCKED_RESULT NTAPI ExInterlockedIncrementLong (IN PLONG Addend, IN PKSPIN_LOCK Lock)
 
INTERLOCKED_RESULT NTAPI ExInterlockedDecrementLong (IN PLONG Addend, IN PKSPIN_LOCK Lock)
 
ULONG NTAPI ExInterlockedExchangeUlong (IN PULONG Target, IN ULONG Value, IN PKSPIN_LOCK Lock)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file interlocked.c.

Function Documentation

◆ _ExiDisableInterruptsAndAcquireSpinlock()

FORCEINLINE BOOLEAN _ExiDisableInterruptsAndAcquireSpinlock ( IN OUT PKSPIN_LOCK  Lock)

Definition at line 32 of file interlocked.c.

34{
36
37 /* Disable interrupts */
39
40 /* Acquire the spinlock (inline) */
41 KxAcquireSpinLock(Lock);
42
43 return Enabled;
44}
unsigned char BOOLEAN
@ Enabled
Definition: mountmgr.h:179
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:239
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

Referenced by ExInterlockedAddLargeInteger(), ExInterlockedAddUlong(), ExInterlockedInsertHeadList(), ExInterlockedInsertTailList(), ExInterlockedPopEntryList(), ExInterlockedPushEntryList(), and ExInterlockedRemoveHeadList().

◆ _ExiReleaseSpinLockAndRestoreInterrupts()

FORCEINLINE VOID _ExiReleaseSpinLockAndRestoreInterrupts ( IN OUT PKSPIN_LOCK  Lock,
BOOLEAN  Enable 
)

Definition at line 48 of file interlocked.c.

51{
52 /* Release the spinlock */
53 KxReleaseSpinLock(Lock);
54
55 /* Restore interrupts */
57}
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:254

Referenced by ExInterlockedAddLargeInteger(), ExInterlockedAddUlong(), ExInterlockedInsertHeadList(), ExInterlockedInsertTailList(), ExInterlockedPopEntryList(), ExInterlockedPushEntryList(), and ExInterlockedRemoveHeadList().

◆ ExInterlockedAddLargeInteger()

LARGE_INTEGER NTAPI ExInterlockedAddLargeInteger ( IN OUT PLARGE_INTEGER  Addend,
IN LARGE_INTEGER  Increment,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 62 of file interlocked.c.

66{
67 LARGE_INTEGER OldValue;
69
70 /* Disable interrupts and acquire the spinlock */
72
73 /* Save the old value */
74 OldValue.QuadPart = Addend->QuadPart;
75
76 /* Do the operation */
77 Addend->QuadPart += Increment.QuadPart;
78
79 /* Release the spinlock and restore interrupts */
81
82 /* Return the old value */
83 return OldValue;
84}
IN OUT PLONG Addend
Definition: CrNtStubs.h:25
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46
FORCEINLINE BOOLEAN _ExiDisableInterruptsAndAcquireSpinlock(IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:32
FORCEINLINE VOID _ExiReleaseSpinLockAndRestoreInterrupts(IN OUT PKSPIN_LOCK Lock, BOOLEAN Enable)
Definition: interlocked.c:48
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by NdisInterlockedAddLargeInteger(), and TestInterlockedFunctional().

◆ ExInterlockedAddUlong()

ULONG NTAPI ExInterlockedAddUlong ( IN OUT PULONG  Addend,
IN ULONG  Increment,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 88 of file interlocked.c.

92{
94 ULONG OldValue;
95
96 /* Disable interrupts and acquire the spinlock */
98
99 /* Save the old value */
100 OldValue = *Addend;
101
102 /* Do the operation */
103 *Addend += Increment;
104
105 /* Release the spinlock and restore interrupts */
107
108 /* Return the old value */
109 return OldValue;
110}
uint32_t ULONG
Definition: typedefs.h:59

Referenced by _Requires_lock_held_(), FatMultiAsyncCompletionRoutine(), FatSingleAsyncCompletionRoutine(), NdisInterlockedAddUlong(), RxCommonWrite(), RxLowIoWriteShellCompletion(), and TestInterlockedFunctional().

◆ ExInterlockedDecrementLong()

INTERLOCKED_RESULT NTAPI ExInterlockedDecrementLong ( IN PLONG  Addend,
IN PKSPIN_LOCK  Lock 
)

Definition at line 267 of file interlocked.c.

270{
271 LONG Result;
272
274 return (Result < 0) ? ResultNegative :
275 (Result > 0) ? ResultPositive :
277}
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)
long LONG
Definition: pedump.c:60
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
@ ResultPositive
Definition: exfuncs.h:361
@ ResultZero
Definition: exfuncs.h:360
@ ResultNegative
Definition: exfuncs.h:359

◆ ExInterlockedExchangeUlong()

ULONG NTAPI ExInterlockedExchangeUlong ( IN PULONG  Target,
IN ULONG  Value,
IN PKSPIN_LOCK  Lock 
)

Definition at line 281 of file interlocked.c.

285{
287}
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
int32_t * PLONG
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

◆ ExInterlockedIncrementLong()

INTERLOCKED_RESULT NTAPI ExInterlockedIncrementLong ( IN PLONG  Addend,
IN PKSPIN_LOCK  Lock 
)

Definition at line 253 of file interlocked.c.

256{
257 LONG Result;
258
260 return (Result < 0) ? ResultNegative :
261 (Result > 0) ? ResultPositive :
263}
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)

◆ ExInterlockedInsertHeadList()

PLIST_ENTRY NTAPI ExInterlockedInsertHeadList ( IN OUT PLIST_ENTRY  ListHead,
IN OUT PLIST_ENTRY  ListEntry,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 114 of file interlocked.c.

118{
120 PLIST_ENTRY FirstEntry;
121
122 /* Disable interrupts and acquire the spinlock */
124
125 /* Save the first entry */
126 FirstEntry = ListHead->Flink;
127
128 /* Insert the new entry */
129 InsertHeadList(ListHead, ListEntry);
130
131 /* Release the spinlock and restore interrupts */
133
134 /* Return the old first entry or NULL for empty list */
135 return (FirstEntry == ListHead) ? NULL : FirstEntry;
136}
#define NULL
Definition: types.h:112
#define InsertHeadList(ListHead, Entry)
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121

Referenced by CcCanIWrite(), CcDeferWrite(), CcPostDeferredWrites(), IopLogWorker(), IoRegisterLastChanceShutdownNotification(), IoRegisterShutdownNotification(), LwipThreadMain(), NdisInterlockedInsertHeadList(), ReadIrpCancel(), START_TEST(), and USBPORT_IsrDpcHandler().

◆ ExInterlockedInsertTailList()

PLIST_ENTRY NTAPI ExInterlockedInsertTailList ( IN OUT PLIST_ENTRY  ListHead,
IN OUT PLIST_ENTRY  ListEntry,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 140 of file interlocked.c.

144{
146 PLIST_ENTRY LastEntry;
147
148 /* Disable interrupts and acquire the spinlock */
150
151 /* Save the last entry */
152 LastEntry = ListHead->Blink;
153
154 /* Insert the new entry */
155 InsertTailList(ListHead, ListEntry);
156
157 /* Release the spinlock and restore interrupts */
159
160 /* Return the old last entry or NULL for empty list */
161 return (LastEntry == ListHead) ? NULL : LastEntry;
162}
#define InsertTailList(ListHead, Entry)
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122

Referenced by _Dispatch_type_(), AfdEventReceiveDatagramHandler(), BindAdapterByName(), CcCanIWrite(), CcDeferWrite(), ChewCreate(), ConnectPortDriver(), ExInitializeNPagedLookasideList(), ExInitializePagedLookasideList(), FdoEnumerateDevices(), FdoStartDevice(), FileOpenAddress(), InsertAudioDevice(), IntVideoPortFindAdapter(), IoInitializeTimer(), IoRegisterBootDriverReinitialization(), IoRegisterDriverReinitialization(), KsAddEvent(), KsDefaultAddEventHandler(), LanCreateProtocol(), LanReadData(), LANRegisterAdapter(), MiInitializeWorkingSetList(), NdisCompleteBindAdapter(), NdisInitializeWrapper(), NdisInterlockedInsertTailList(), NdisIPnPStartDevice(), NdisOpenAdapter(), NdisReadConfiguration(), NdisReadNetworkAddress(), NdisRegisterProtocol(), NduReceive(), START_TEST(), sys_mbox_post(), TCPAllocateConnectionEndpoint(), TcpipInterlockedInsertTailList(), USBH_QueueWorkItem(), USBPORT_AddUSB1Fdo(), USBPORT_AddUSB2Fdo(), USBPORT_DeleteEndpoint(), USBPORT_EndpointWorker(), USBPORT_OpenPipe(), USBPORT_QueueDoneTransfer(), USBPORT_RegisterUSBPortDriver(), USBPORT_RootHubEndpointWorker(), USBPORT_SetEndpointState(), VfdDeviceControl(), VfdReadWrite(), and WdmAudOpenSysaudio().

◆ ExInterlockedPopEntryList()

PSINGLE_LIST_ENTRY NTAPI ExInterlockedPopEntryList ( IN OUT PSINGLE_LIST_ENTRY  ListHead,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 201 of file interlocked.c.

204{
206 PSINGLE_LIST_ENTRY ListEntry;
207
208 /* Disable interrupts and acquire the spinlock */
210
211 /* Pop the first entry from the list */
212 ListEntry = PopEntryList(ListHead);
213#if DBG
214 if (ListEntry)
215 ListEntry->Next = (PSINGLE_LIST_ENTRY)(ULONG_PTR)0xBADDD0FFBADDD0FFULL;
216#endif
217
218 /* Release the spinlock and restore interrupts */
220
221 /* Return the entry */
222 return ListEntry;
223}
struct _SINGLE_LIST_ENTRY * PSINGLE_LIST_ENTRY
Definition: ntbasedef.h:636
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:637
uint32_t ULONG_PTR
Definition: typedefs.h:65
FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: rtlfuncs.h:243

Referenced by DiskReregWorker().

◆ ExInterlockedPushEntryList()

PSINGLE_LIST_ENTRY NTAPI ExInterlockedPushEntryList ( IN OUT PSINGLE_LIST_ENTRY  ListHead,
IN OUT PSINGLE_LIST_ENTRY  ListEntry,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 227 of file interlocked.c.

231{
233 PSINGLE_LIST_ENTRY OldListEntry;
234
235 /* Disable interrupts and acquire the spinlock */
237
238 /* Save the old top entry */
239 OldListEntry = ListHead->Next;
240
241 /* Push a new entry on the list */
242 PushEntryList(ListHead, ListEntry);
243
244 /* Release the spinlock and restore interrupts */
246
247 /* Return the entry */
248 return OldListEntry;
249}
FORCEINLINE VOID PushEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PSINGLE_LIST_ENTRY Entry)
Definition: rtlfuncs.h:256

Referenced by DiskPostReregisterRequest().

◆ ExInterlockedRemoveHeadList()

PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList ( IN OUT PLIST_ENTRY  ListHead,
IN OUT PKSPIN_LOCK  Lock 
)

Definition at line 166 of file interlocked.c.

169{
171 PLIST_ENTRY ListEntry;
172
173 /* Disable interrupts and acquire the spinlock */
175
176 /* Check if the list is empty */
177 if (IsListEmpty(ListHead))
178 {
179 /* Return NULL */
180 ListEntry = NULL;
181 }
182 else
183 {
184 /* Remove the first entry from the list head */
185 ListEntry = RemoveHeadList(ListHead);
186#if DBG
187 ListEntry->Flink = (PLIST_ENTRY)(ULONG_PTR)0xBADDD0FFBADDD0FFULL;
188 ListEntry->Blink = (PLIST_ENTRY)(ULONG_PTR)0xBADDD0FFBADDD0FFULL;
189#endif
190 }
191
192 /* Release the spinlock and restore interrupts */
194
195 /* Return the entry */
196 return ListEntry;
197}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
struct _LIST_ENTRY * PLIST_ENTRY

Referenced by CcPostDeferredWrites(), IopReinitializeBootDrivers(), IopReinitializeDrivers(), IoShutdownSystem(), LoadSymbolsRoutine(), NBSendPackets(), NdisCloseConfiguration(), NdisInterlockedRemoveHeadList(), START_TEST(), sys_shutdown(), USBH_FlushPortPwrList(), USBPORT_IsrDpcHandler(), and VfdDeviceThread().