3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/interlck.c
6 * PURPOSE: Implements interlocked functions
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
16 #include <internal/debug.h>
18 /* FUNCTIONS *****************************************************************/
20 #undef ExInterlockedDecrementLong
25 INTERLOCKED_RESULT STDCALL
26 ExInterlockedDecrementLong (PLONG Addend
,
29 * Obsolete, use InterlockedDecrement instead
35 KeAcquireSpinLock (Lock
, &oldlvl
);
40 KeReleaseSpinLock (Lock
, oldlvl
);
45 #undef ExInterlockedExchangeUlong
51 ExInterlockedExchangeUlong (PULONG Target
,
55 * Obsolete, use InterlockedExchange instead
61 KeAcquireSpinLock (Lock
, &oldlvl
);
66 KeReleaseSpinLock (Lock
, oldlvl
);
72 #undef ExInterlockedAddUlong
78 ExInterlockedAddUlong (PULONG Addend
,
82 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
83 * integer as an atomic operation.
85 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
86 * by the Increment value.
88 * INCREMENT = Is an unsigned long integer to be added.
90 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
94 * The original value of the unsigned integer pointed to by ADDEND.
100 KeAcquireSpinLock (Lock
, &oldlvl
);
103 *Addend
+= Increment
;
105 KeReleaseSpinLock (Lock
, oldlvl
);
113 LARGE_INTEGER STDCALL
114 ExInterlockedAddLargeInteger (PLARGE_INTEGER Addend
,
115 LARGE_INTEGER Increment
,
118 * Adds two large integer values as an atomic operation.
120 * ADDEND = Pointer to a large integer value that will have INCREMENT added.
122 * INCREMENT = Value to be added.
124 * LOCK = Spinlock used to synchronize access to ADDEND.
128 * The original value of the large integer pointed to by ADDEND.
132 LARGE_INTEGER oldval
;
135 KeAcquireSpinLock (Lock
, &oldlvl
);
138 oldval
.QuadPart
= Addend
->QuadPart
;
139 Addend
->QuadPart
+= Increment
.QuadPart
;
141 KeReleaseSpinLock (Lock
, oldlvl
);
146 #undef ExInterlockedIncrementLong
151 INTERLOCKED_RESULT STDCALL
152 ExInterlockedIncrementLong (PLONG Addend
,
155 * Obsolete, use InterlockedIncrement instead.
161 KeAcquireSpinLock (Lock
, &oldlvl
);
166 KeReleaseSpinLock (Lock
, oldlvl
);
175 ExInterlockedAddLargeStatistic (IN PLARGE_INTEGER Addend
,
178 * Undocumented in DDK.
181 Addend
->QuadPart
+= Increment
;
188 ExInterlockedCompareExchange64 (IN OUT PLONGLONG Destination
,
189 IN PLONGLONG Exchange
,
190 IN PLONGLONG Comparand
,
193 * Undocumented in DDK.
199 KeAcquireSpinLock (Lock
, &oldlvl
);
201 oldval
= *Destination
;
202 if (*Destination
== *Comparand
)
204 *Destination
= *Exchange
;
207 KeReleaseSpinLock (Lock
, oldlvl
);
216 ExfInterlockedAddUlong(PULONG Addend
,
220 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
221 * integer as an atomic operation.
223 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
224 * by the Increment value.
226 * INCREMENT = Is an unsigned long integer to be added.
228 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
232 * The original value of the unsigned integer pointed to by ADDEND.
238 KeAcquireSpinLock (Lock
, &oldlvl
);
241 *Addend
+= Increment
;
243 KeReleaseSpinLock (Lock
, oldlvl
);