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 *****************************************************************/
14 #include <ddk/ntddk.h>
17 /* FUNCTIONS *****************************************************************/
19 INTERLOCKED_RESULT STDCALL
20 ExInterlockedDecrementLong (PLONG Addend,
23 * Obsolete, use InterlockedDecrement instead
29 KeAcquireSpinLock (Lock, &oldlvl);
34 KeReleaseSpinLock (Lock, oldlvl);
41 ExInterlockedExchangeUlong (PULONG Target,
45 * Obsolete, use InterlockedExchange instead
51 KeAcquireSpinLock (Lock, &oldlvl);
56 KeReleaseSpinLock (Lock, oldlvl);
63 ExInterlockedAddUlong (PULONG Addend,
67 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
68 * integer as an atomic operation.
70 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
71 * by the Increment value.
73 * INCREMENT = Is an unsigned long integer to be added.
75 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
79 * The original value of the unsigned integer pointed to by ADDEND.
85 KeAcquireSpinLock (Lock, &oldlvl);
90 KeReleaseSpinLock (Lock, oldlvl);
96 ExInterlockedAddLargeInteger (PLARGE_INTEGER Addend,
97 LARGE_INTEGER Increment,
100 * Adds two large integer values as an atomic operation.
102 * ADDEND = Pointer to a large integer value that will have INCREMENT added.
104 * INCREMENT = Value to be added.
106 * LOCK = Spinlock used to synchronize access to ADDEND.
110 * The original value of the large integer pointed to by ADDEND.
114 LARGE_INTEGER oldval;
117 KeAcquireSpinLock (Lock, &oldlvl);
120 oldval.QuadPart = Addend->QuadPart;
121 Addend->QuadPart += Increment.QuadPart;
123 KeReleaseSpinLock (Lock, oldlvl);
128 INTERLOCKED_RESULT STDCALL
129 ExInterlockedIncrementLong (PLONG Addend,
132 * Obsolete, use InterlockedIncrement instead.
138 KeAcquireSpinLock (Lock, &oldlvl);
143 KeReleaseSpinLock (Lock, oldlvl);
149 ExInterlockedAddLargeStatistic (IN PLARGE_INTEGER Addend,
152 * Undocumented in DDK.
155 Addend->QuadPart += Increment;
159 ExInterlockedCompareExchange64 (IN OUT PLONGLONG Destination,
160 IN PLONGLONG Exchange,
161 IN PLONGLONG Comparand,
164 * Undocumented in DDK.
170 KeAcquireSpinLock (Lock, &oldlvl);
172 oldval = *Destination;
173 if (*Destination == *Comparand)
175 *Destination = *Exchange;
178 KeReleaseSpinLock (Lock, oldlvl);
184 ExfInterlockedAddUlong(PULONG Addend,
188 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
189 * integer as an atomic operation.
191 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
192 * by the Increment value.
194 * INCREMENT = Is an unsigned long integer to be added.
196 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
200 * The original value of the unsigned integer pointed to by ADDEND.
206 KeAcquireSpinLock (Lock, &oldlvl);
209 *Addend += Increment;
211 KeReleaseSpinLock (Lock, oldlvl);