Reverted latest changes.
[reactos.git] / reactos / ntoskrnl / ex / interlck.c
1 /* $Id: interlck.c,v 1.9 2002/09/08 10:23:19 chorns Exp $
2 *
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)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15
16
17 /* FUNCTIONS *****************************************************************/
18
19 INTERLOCKED_RESULT STDCALL
20 ExInterlockedDecrementLong (PLONG Addend,
21 PKSPIN_LOCK Lock)
22 /*
23 * Obsolete, use InterlockedDecrement instead
24 */
25 {
26 KIRQL oldlvl;
27 LONG oldval;
28
29 KeAcquireSpinLock (Lock, &oldlvl);
30
31 oldval = *Addend;
32 (*Addend)--;
33
34 KeReleaseSpinLock (Lock, oldlvl);
35
36 return oldval;
37 }
38
39
40 ULONG STDCALL
41 ExInterlockedExchangeUlong (PULONG Target,
42 ULONG Value,
43 PKSPIN_LOCK Lock)
44 /*
45 * Obsolete, use InterlockedExchange instead
46 */
47 {
48 KIRQL oldlvl;
49 LONG oldval;
50
51 KeAcquireSpinLock (Lock, &oldlvl);
52
53 oldval = *Target;
54 *Target = Value;
55
56 KeReleaseSpinLock (Lock, oldlvl);
57
58 return oldval;
59 }
60
61
62 ULONG STDCALL
63 ExInterlockedAddUlong (PULONG Addend,
64 ULONG Increment,
65 PKSPIN_LOCK Lock)
66 /*
67 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
68 * integer as an atomic operation.
69 *
70 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
71 * by the Increment value.
72 *
73 * INCREMENT = Is an unsigned long integer to be added.
74 *
75 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
76 *
77 * Returns:
78 *
79 * The original value of the unsigned integer pointed to by ADDEND.
80 */
81 {
82 KIRQL oldlvl;
83 ULONG oldval;
84
85 KeAcquireSpinLock (Lock, &oldlvl);
86
87 oldval = *Addend;
88 *Addend += Increment;
89
90 KeReleaseSpinLock (Lock, oldlvl);
91
92 return oldval;
93 }
94
95 LARGE_INTEGER STDCALL
96 ExInterlockedAddLargeInteger (PLARGE_INTEGER Addend,
97 LARGE_INTEGER Increment,
98 PKSPIN_LOCK Lock)
99 /*
100 * Adds two large integer values as an atomic operation.
101 *
102 * ADDEND = Pointer to a large integer value that will have INCREMENT added.
103 *
104 * INCREMENT = Value to be added.
105 *
106 * LOCK = Spinlock used to synchronize access to ADDEND.
107 *
108 * Returns:
109 *
110 * The original value of the large integer pointed to by ADDEND.
111 */
112 {
113 KIRQL oldlvl;
114 LARGE_INTEGER oldval;
115
116
117 KeAcquireSpinLock (Lock, &oldlvl);
118
119
120 oldval.QuadPart = Addend->QuadPart;
121 Addend->QuadPart += Increment.QuadPart;
122
123 KeReleaseSpinLock (Lock, oldlvl);
124
125 return oldval;
126 }
127
128 INTERLOCKED_RESULT STDCALL
129 ExInterlockedIncrementLong (PLONG Addend,
130 PKSPIN_LOCK Lock)
131 /*
132 * Obsolete, use InterlockedIncrement instead.
133 */
134 {
135 KIRQL oldlvl;
136 LONG oldval;
137
138 KeAcquireSpinLock (Lock, &oldlvl);
139
140 oldval = *Addend;
141 (*Addend)++;
142
143 KeReleaseSpinLock (Lock, oldlvl);
144
145 return oldval;
146 }
147
148 VOID FASTCALL
149 ExInterlockedAddLargeStatistic (IN PLARGE_INTEGER Addend,
150 IN ULONG Increment)
151 /*
152 * Undocumented in DDK.
153 */
154 {
155 Addend->QuadPart += Increment;
156 }
157
158 LONGLONG FASTCALL
159 ExInterlockedCompareExchange64 (IN OUT PLONGLONG Destination,
160 IN PLONGLONG Exchange,
161 IN PLONGLONG Comparand,
162 IN PKSPIN_LOCK Lock)
163 /*
164 * Undocumented in DDK.
165 */
166 {
167 KIRQL oldlvl;
168 LONGLONG oldval;
169
170 KeAcquireSpinLock (Lock, &oldlvl);
171
172 oldval = *Destination;
173 if (*Destination == *Comparand)
174 {
175 *Destination = *Exchange;
176 }
177
178 KeReleaseSpinLock (Lock, oldlvl);
179
180 return oldval;
181 }
182
183 ULONG FASTCALL
184 ExfInterlockedAddUlong(PULONG Addend,
185 ULONG Increment,
186 PKSPIN_LOCK Lock)
187 /*
188 * ExInterlockedAddUlong adds an unsigned long value to a given unsigned
189 * integer as an atomic operation.
190 *
191 * ADDEND = Points to an unsigned long integer whose value is to be adjusted
192 * by the Increment value.
193 *
194 * INCREMENT = Is an unsigned long integer to be added.
195 *
196 * LOCK = Points to a spinlock to be used to synchronize access to ADDEND.
197 *
198 * Returns:
199 *
200 * The original value of the unsigned integer pointed to by ADDEND.
201 */
202 {
203 KIRQL oldlvl;
204 ULONG oldval;
205
206 KeAcquireSpinLock (Lock, &oldlvl);
207
208 oldval = *Addend;
209 *Addend += Increment;
210
211 KeReleaseSpinLock (Lock, oldlvl);
212
213 return oldval;
214 }
215
216 /* EOF */