3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/interlck.c
6 * PURPOSE: Implements interlocked functions
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
11 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 /* FUNCTIONS *****************************************************************/
19 #undef ExInterlockedDecrementLong
24 INTERLOCKED_RESULT STDCALL
25 ExInterlockedDecrementLong (PLONG Addend
,
28 * Obsolete, use InterlockedDecrement instead
34 KeAcquireSpinLock (Lock
, &oldlvl
);
39 KeReleaseSpinLock (Lock
, oldlvl
);
44 #undef ExInterlockedExchangeUlong
50 ExInterlockedExchangeUlong (PULONG Target
,
54 * Obsolete, use InterlockedExchange instead
60 KeAcquireSpinLock (Lock
, &oldlvl
);
65 KeReleaseSpinLock (Lock
, oldlvl
);
71 #undef ExInterlockedAddUlong
77 ExInterlockedAddUlong (PULONG Addend
,
81 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
82 * integer as an atomic operation.
84 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
85 * by the Increment value.
87 * INCREMENT = Is an unsigned long integer to be added.
89 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
93 * The original value of the unsigned integer pointed to by ADDEND.
99 KeAcquireSpinLock (Lock
, &oldlvl
);
102 *Addend
+= Increment
;
104 KeReleaseSpinLock (Lock
, oldlvl
);
112 LARGE_INTEGER STDCALL
113 ExInterlockedAddLargeInteger (PLARGE_INTEGER Addend
,
114 LARGE_INTEGER Increment
,
117 * Adds two large integer values as an atomic operation.
119 * ADDEND = Pointer to a large integer value that will have INCREMENT added.
121 * INCREMENT = Value to be added.
123 * LOCK = Spinlock used to synchronize access to ADDEND.
127 * The original value of the large integer pointed to by ADDEND.
131 LARGE_INTEGER oldval
;
134 KeAcquireSpinLock (Lock
, &oldlvl
);
137 oldval
.QuadPart
= Addend
->QuadPart
;
138 Addend
->QuadPart
+= Increment
.QuadPart
;
140 KeReleaseSpinLock (Lock
, oldlvl
);
145 #undef ExInterlockedIncrementLong
150 INTERLOCKED_RESULT STDCALL
151 ExInterlockedIncrementLong (PLONG Addend
,
154 * Obsolete, use InterlockedIncrement instead.
160 KeAcquireSpinLock (Lock
, &oldlvl
);
165 KeReleaseSpinLock (Lock
, oldlvl
);
174 ExInterlockedAddLargeStatistic (IN PLARGE_INTEGER Addend
,
177 * Undocumented in DDK.
180 Addend
->QuadPart
+= Increment
;
187 ExInterlockedCompareExchange64 (IN OUT PLONGLONG Destination
,
188 IN PLONGLONG Exchange
,
189 IN PLONGLONG Comparand
,
192 * Undocumented in DDK.
198 KeAcquireSpinLock (Lock
, &oldlvl
);
200 oldval
= *Destination
;
201 if (*Destination
== *Comparand
)
203 *Destination
= *Exchange
;
206 KeReleaseSpinLock (Lock
, oldlvl
);
215 ExfInterlockedAddUlong(PULONG Addend
,
219 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
220 * integer as an atomic operation.
222 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
223 * by the Increment value.
225 * INCREMENT = Is an unsigned long integer to be added.
227 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
231 * The original value of the unsigned integer pointed to by ADDEND.
237 KeAcquireSpinLock (Lock
, &oldlvl
);
240 *Addend
+= Increment
;
242 KeReleaseSpinLock (Lock
, oldlvl
);