xref: /reactos/sdk/include/xdk/interlocked.h (revision 96051109)
1 /******************************************************************************
2  *                           INTERLOCKED Functions                            *
3  ******************************************************************************/
4 
5 #define BitScanForward _BitScanForward
6 #define BitScanReverse _BitScanReverse
7 #define BitTest _bittest
8 #define BitTestAndComplement _bittestandcomplement
9 #define BitTestAndSet _bittestandset
10 #define BitTestAndReset _bittestandreset
11 #ifdef _WIN64
12 #define BitScanForward64 _BitScanForward64
13 #define BitScanReverse64 _BitScanReverse64
14 #define BitTest64 _bittest64
15 #define BitTestAndComplement64 _bittestandcomplement64
16 #define BitTestAndSet64 _bittestandset64
17 #define BitTestAndReset64 _bittestandreset64
18 #endif /* _WIN64 */
19 
20 #if defined(_M_ARM) || defined(_M_IA64)
21 #define __ACQ_(x) x##_acq
22 #define __REL_(x) x##_rel
23 #define __NF_(x) x##_nf
24 #else
25 #define __ACQ_(x) x
26 #define __REL_(x) x
27 #define __NF_(x) x
28 #endif
29 
30 #define InterlockedBitTestAndSet _interlockedbittestandset
31 #define InterlockedBitTestAndSetAcquire __ACQ_(_interlockedbittestandset)
32 #define InterlockedBitTestAndSetRelease __REL_(_interlockedbittestandset)
33 #define InterlockedBitTestAndSetNoFence __NF_(_interlockedbittestandset)
34 
35 #define InterlockedBitTestAndReset _interlockedbittestandreset
36 #define InterlockedBitTestAndResetAcquire __ACQ_(_interlockedbittestandreset)
37 #define InterlockedBitTestAndResetRelease __REL_(_interlockedbittestandreset)
38 #define InterlockedBitTestAndResetNoFence __NF_(_interlockedbittestandreset)
39 
40 #ifdef _WIN64
41 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
42 #define InterlockedBitTestAndSet64Acquire __ACQ_(_interlockedbittestandset64)
43 #define InterlockedBitTestAndSet64Release __REL_(_interlockedbittestandset64)
44 #define InterlockedBitTestAndSet64NoFence __NF_(_interlockedbittestandset64)
45 
46 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
47 #define InterlockedBitTestAndReset64Acquire __ACQ_(_interlockedbittestandreset64)
48 #define InterlockedBitTestAndReset64Release __REL_(_interlockedbittestandreset64)
49 #define InterlockedBitTestAndReset64NoFence __NF_(_interlockedbittestandreset64)
50 #endif /* _WIN64 */
51 
52 #define InterlockedAdd _InterlockedAdd
53 #define InterlockedAddAcquire __ACQ_(_InterlockedAdd)
54 #define InterlockedAddRelease __REL_(_InterlockedAdd)
55 #define InterlockedAddNoFence __NF_(_InterlockedAdd)
56 
57 #define InterlockedAdd64 _InterlockedAdd64
58 #define InterlockedAddAcquire64 __ACQ_(_InterlockedAdd64)
59 #define InterlockedAddRelease64 __REL_(_InterlockedAdd64)
60 #define InterlockedAddNoFence64 __NF_(_InterlockedAdd64)
61 
62 #define InterlockedAnd _InterlockedAnd
63 #define InterlockedAndAcquire __ACQ_(_InterlockedAnd)
64 #define InterlockedAndRelease __REL_(_InterlockedAnd)
65 #define InterlockedAndNoFence __NF_(_InterlockedAnd)
66 
67 #define InterlockedAnd8 _InterlockedAnd8
68 #ifdef _M_ARM
69 #define InterlockedAndAcquire8 _InterlockedAnd8_acq
70 #define InterlockedAndRelease8 _InterlockedAnd8_rel
71 #define InterlockedAndNoFence8 _InterlockedAnd8_nf
72 #elif defined(_M_IA64)
73 #define InterlockedAnd8Acquire  _InterlockedAnd8_acq
74 #define InterlockedAnd8Release  _InterlockedAnd8_rel
75 #endif // _M_ARM
76 
77 #define InterlockedAnd16 _InterlockedAnd16
78 #ifdef _M_ARM
79 #define InterlockedAndAcquire16 _InterlockedAnd16_acq
80 #define InterlockedAndRelease16 _InterlockedAnd16_rel
81 #define InterlockedAndNoFence16 _InterlockedAnd16_nf
82 #elif defined(_M_IA64)
83 #define InterlockedAnd16Acquire _InterlockedAnd16_acq
84 #define InterlockedAnd16Release _InterlockedAnd16_rel
85 #endif // _M_ARM
86 
87 #define InterlockedAnd64 _InterlockedAnd64
88 #ifdef _M_ARM
89 #define InterlockedAndAcquire64 __ACQ_(_InterlockedAnd64)
90 #define InterlockedAndRelease64 __REL_(_InterlockedAnd64)
91 #define InterlockedAndNoFence64 __NF_(_InterlockedAnd64)
92 #else // _M_ARM
93 #define InterlockedAnd64Acquire __ACQ_(_InterlockedAnd64)
94 #define InterlockedAnd64Release __REL_(_InterlockedAnd64)
95 #define InterlockedAnd64NoFence __NF_(_InterlockedAnd64)
96 #endif // _M_ARM
97 
98 #ifdef _WIN64
99 #define InterlockedAndAffinity InterlockedAnd64
100 #else
101 #define InterlockedAndAffinity InterlockedAnd
102 #endif // _WIN64
103 
104 #define InterlockedCompareExchange _InterlockedCompareExchange
105 #define InterlockedCompareExchangeAcquire __ACQ_(_InterlockedCompareExchange)
106 #define InterlockedCompareExchangeRelease __REL_(_InterlockedCompareExchange)
107 #define InterlockedCompareExchangeNoFence __NF_(_InterlockedCompareExchange)
108 
109 #define InterlockedCompareExchange16 _InterlockedCompareExchange16
110 #define InterlockedCompareExchangeAcquire16 __ACQ_(_InterlockedCompareExchange16)
111 #define InterlockedCompareExchangeRelease16 __REL_(_InterlockedCompareExchange16)
112 #define InterlockedCompareExchangeNoFence16 __NF_(_InterlockedCompareExchange16)
113 
114 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
115 #define InterlockedCompareExchangeAcquire64 __ACQ_(_InterlockedCompareExchange64)
116 #define InterlockedCompareExchangeRelease64 __REL_(_InterlockedCompareExchange64)
117 #define InterlockedCompareExchangeNoFence64 __NF_(_InterlockedCompareExchange64)
118 
119 #ifdef _WIN64
120 #define InterlockedCompareExchange128 _InterlockedCompareExchange128
121 #endif // _WIN64
122 
123 #ifdef _M_IA64
124 #define InterlockedCompare64Exchange128         _InterlockedCompare64Exchange128
125 #define InterlockedCompare64ExchangeAcquire128  _InterlockedCompare64Exchange128_acq
126 #define InterlockedCompare64ExchangeRelease128  _InterlockedCompare64Exchange128_rel
127 #endif // _M_IA64
128 
129 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
130 #define InterlockedCompareExchangePointerAcquire __ACQ_(_InterlockedCompareExchangePointer)
131 #define InterlockedCompareExchangePointerRelease __REL_(_InterlockedCompareExchangePointer)
132 #define InterlockedCompareExchangePointerNoFence __NF_(_InterlockedCompareExchangePointer)
133 
134 #define InterlockedDecrement _InterlockedDecrement
135 #define InterlockedDecrementAcquire __ACQ_(_InterlockedDecrement)
136 #define InterlockedDecrementRelease __REL_(_InterlockedDecrement)
137 #define InterlockedDecrementNoFence __NF_(_InterlockedDecrement)
138 
139 #define InterlockedDecrement16 _InterlockedDecrement16
140 #define InterlockedDecrementAcquire16 __ACQ_(_InterlockedDecrement16)
141 #define InterlockedDecrementRelease16 __REL_(_InterlockedDecrement16)
142 #define InterlockedDecrementNoFence16 __NF_(_InterlockedDecrement16)
143 
144 #define InterlockedDecrement64 _InterlockedDecrement64
145 #define InterlockedDecrementAcquire64 __ACQ_(_InterlockedDecrement64)
146 #define InterlockedDecrementRelease64 __REL_(_InterlockedDecrement64)
147 #define InterlockedDecrementNoFence64 __NF_(_InterlockedDecrement64)
148 
149 #ifdef _WIN64
150 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONG64 *)a)
151 #define InterlockedDecrementSizeTNoFence(a) InterlockedDecrementNoFence64((LONG64 *)a)
152 #else
153 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
154 #define InterlockedDecrementSizeTNoFence(a) InterlockedDecrementNoFence((LONG *)a)
155 #endif // _WIN64
156 
157 #define InterlockedExchange _InterlockedExchange
158 #define InterlockedExchangeAcquire __ACQ_(_InterlockedExchange)
159 /* No release here */
160 #define InterlockedExchangeNoFence __NF_(_InterlockedExchange)
161 
162 #if (_MSC_VER >= 1600)
163 #define InterlockedExchange8 _InterlockedExchange8
164 #endif // (_MSC_VER >= 1600)
165 
166 #define InterlockedExchange16 _InterlockedExchange16
167 /* No release here */
168 #define InterlockedExchangeAcquire16 __ACQ_(_InterlockedExchange16)
169 #define InterlockedExchangeNoFence16 __NF_(_InterlockedExchange16)
170 
171 #define InterlockedExchange64 _InterlockedExchange64
172 #define InterlockedExchangeAcquire64 __ACQ_(_InterlockedExchange64)
173 /* No release here */
174 #define InterlockedExchangeNoFence64 __NF_(_InterlockedExchange64)
175 
176 #define InterlockedExchangePointer _InterlockedExchangePointer
177 #define InterlockedExchangePointerAcquire __ACQ_(_InterlockedExchangePointer)
178 /* No release here */
179 #define InterlockedExchangePointerNoFence __NF_(_InterlockedExchangePointer)
180 
181 #define InterlockedExchangeAdd _InterlockedExchangeAdd
182 #define InterlockedExchangeAddAcquire __ACQ_(_InterlockedExchangeAdd)
183 #define InterlockedExchangeAddRelease __REL_(_InterlockedExchangeAdd)
184 #define InterlockedExchangeAddNoFence __NF_(_InterlockedExchangeAdd)
185 
186 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
187 #define InterlockedExchangeAddAcquire64 __ACQ_(_InterlockedExchangeAdd64)
188 #define InterlockedExchangeAddRelease64 __REL_(_InterlockedExchangeAdd64)
189 #define InterlockedExchangeAddNoFence64 __NF_(_InterlockedExchangeAdd64)
190 
191 #ifdef _WIN64
192 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONG64 *)a, b)
193 #define InterlockedExchangeAddSizeTAcquire(a, b) InterlockedExchangeAddAcquire64((LONG64 *)a, b)
194 #define InterlockedExchangeAddSizeTNoFence(a, b) InterlockedExchangeAddNoFence64((LONG64 *)a, b)
195 #else
196 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
197 #define InterlockedExchangeAddSizeTAcquire(a, b) InterlockedExchangeAddAcquire((LONG *)a, b)
198 #define InterlockedExchangeAddSizeTNoFence(a, b) InterlockedExchangeAddNoFence((LONG *)a, b)
199 #endif // _WIN64
200 
201 #define InterlockedIncrement _InterlockedIncrement
202 #define InterlockedIncrementAcquire __ACQ_(_InterlockedIncrement)
203 #define InterlockedIncrementRelease __REL_(_InterlockedIncrement)
204 #define InterlockedIncrementNoFence __NF_(_InterlockedIncrement)
205 
206 #define InterlockedIncrement16 _InterlockedIncrement16
207 #define InterlockedIncrementAcquire16 __ACQ_(_InterlockedIncrement16)
208 #define InterlockedIncrementRelease16 __REL_(_InterlockedIncrement16)
209 #define InterlockedIncrementNoFence16 __NF_(_InterlockedIncrement16)
210 
211 #define InterlockedIncrement64 _InterlockedIncrement64
212 #define InterlockedIncrementAcquire64 __ACQ_(_InterlockedIncrement64)
213 #define InterlockedIncrementRelease64 __REL_(_InterlockedIncrement64)
214 #define InterlockedIncrementNoFence64 __NF_(_InterlockedIncrement64)
215 
216 #ifdef _WIN64
217 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONG64 *)a)
218 #define InterlockedIncrementSizeTNoFence(a) InterlockedIncrementNoFence64((LONG64 *)a)
219 #else
220 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
221 #define InterlockedIncrementSizeTNoFence(a) InterlockedIncrementNoFence((LONG *)a)
222 #endif // _WIN64
223 
224 #define InterlockedOr _InterlockedOr
225 #define InterlockedOrAcquire __ACQ_(_InterlockedOr)
226 #define InterlockedOrRelease __REL_(_InterlockedOr)
227 #define InterlockedOrNoFence __NF_(_InterlockedOr)
228 
229 #define InterlockedOr8 _InterlockedOr8
230 #ifdef _M_ARM
231 #define InterlockedOrAcquire8 _InterlockedOr8_acq
232 #define InterlockedOrRelease8 _InterlockedOr8_rel
233 #define InterlockedOrNoFence8 _InterlockedOr8_nf
234 #elif defined(_M_IA64)
235 #define InterlockedOr8Acquire  _InterlockedOr8_acq
236 #define InterlockedOr8Release  _InterlockedOr8_rel
237 #endif // _M_ARM
238 
239 #define InterlockedOr16 _InterlockedOr16
240 #ifdef _M_ARM
241 #define InterlockedOrAcquire16 _InterlockedOr16_acq
242 #define InterlockedOrRelease16 _InterlockedOr16_rel
243 #define InterlockedOrNoFence16 _InterlockedOr16_nf
244 #elif defined(_M_IA64)
245 #define InterlockedOr16Acquire _InterlockedOr16_acq
246 #define InterlockedOr16Release _InterlockedOr16_rel
247 #endif // _M_ARM
248 
249 #define InterlockedOr64 _InterlockedOr64
250 #ifdef _M_ARM
251 #define InterlockedOrAcquire64 _InterlockedOr64_acq
252 #define InterlockedOrRelease64 _InterlockedOr64_rel
253 #define InterlockedOrNoFence64 _InterlockedOr64_nf
254 #elif defined(_M_IA64) || defined(_M_AMD64)
255 #define InterlockedOr64Acquire __ACQ_(_InterlockedOr64)
256 #define InterlockedOr64Release __REL_(_InterlockedOr64)
257 #define InterlockedOr64NoFence __NF_(_InterlockedOr64)
258 #endif // _M_ARM
259 
260 #ifdef _WIN64
261 #define InterlockedOrAffinity InterlockedOr64
262 #else
263 #define InterlockedOrAffinity InterlockedOr
264 #endif // _WIN64
265 
266 #define InterlockedXor _InterlockedXor
267 #define InterlockedXorAcquire __ACQ_(_InterlockedXor)
268 #define InterlockedXorRelease __REL_(_InterlockedXor)
269 #define InterlockedXorNoFence __NF_(_InterlockedXor)
270 
271 #define InterlockedXor8 _InterlockedXor8
272 #ifdef _M_ARM
273 #define InterlockedXorAcquire8 _InterlockedXor8_acq
274 #define InterlockedXorRelease8 _InterlockedXor8_rel
275 #define InterlockedXorNoFence8 _InterlockedXor8_nf
276 #elif defined(_M_IA64)
277 #define InterlockedXor8Acquire _InterlockedXor8_acq
278 #define InterlockedXor8Release _InterlockedXor8_rel
279 #endif /* _M_ARM */
280 
281 #define InterlockedXor16 _InterlockedXor16
282 #ifdef _M_ARM
283 #define InterlockedXorAcquire16 _InterlockedXor16_acq
284 #define InterlockedXorRelease16 _InterlockedXor16_rel
285 #define InterlockedXorNoFence16 _InterlockedXor16_nf
286 #elif defined(_M_IA64)
287 #define InterlockedXor16Acquire _InterlockedXor16_acq
288 #define InterlockedXor16Release _InterlockedXor16_rel
289 #endif /* _M_ARM */
290 
291 #define InterlockedXor64 _InterlockedXor64
292 #ifdef _M_ARM
293 #define InterlockedXorAcquire64 _InterlockedXor64_acq
294 #define InterlockedXorRelease64 _InterlockedXor64_rel
295 #define InterlockedXorNoFence64 _InterlockedXor64_nf
296 #elif defined(_M_IA64) || defined(_M_AMD64)
297 #define InterlockedXor64Acquire __ACQ_(_InterlockedXor64)
298 #define InterlockedXor64Release __REL_(_InterlockedXor64)
299 #define InterlockedXor64NoFence __NF_(_InterlockedXor64)
300 #endif /* _M_ARM */
301 
302 #ifdef _M_IX86
303 
304 #undef _InterlockedExchange64
305 #define _InterlockedExchange64 _InlineInterlockedExchange64
306 FORCEINLINE
307 LONG64
_InlineInterlockedExchange64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)308 _InlineInterlockedExchange64(
309     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
310     _In_ LONG64 Value)
311 {
312     LONG64 Old, Prev;
313     for (Old = *Target; ; Old = Prev)
314     {
315         Prev = _InterlockedCompareExchange64(Target, Value, Old);
316         if (Prev == Old)
317             return Prev;
318     }
319 }
320 
321 #undef _InterlockedAdd64
322 #define _InterlockedAdd64 _InlineInterlockedAdd64
323 FORCEINLINE
324 LONG64
_InlineInterlockedAdd64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)325 _InlineInterlockedAdd64(
326     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
327     _In_ LONG64 Value)
328 {
329     LONG64 Old, Prev, New;
330     for (Old = *Target; ; Old = Prev)
331     {
332         New = Old + Value;
333         Prev = _InterlockedCompareExchange64(Target, New, Old);
334         if (Prev == Old)
335             return New;
336     }
337 }
338 
339 #undef _InterlockedExchangeAdd64
340 #define _InterlockedExchangeAdd64 _InlineInterlockedExchangeAdd64
341 FORCEINLINE
342 LONG64
_InlineInterlockedExchangeAdd64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)343 _InlineInterlockedExchangeAdd64(
344     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
345     _In_ LONG64 Value
346     )
347 {
348     LONG64 Old, Prev, New;
349     for (Old = *Target; ; Old = Prev)
350     {
351         New = Old + Value;
352         Prev = _InterlockedCompareExchange64(Target, New, Old);
353         if (Prev == Old)
354             return Prev;
355     }
356 }
357 
358 #undef _InterlockedAnd64
359 #define _InterlockedAnd64 _InlineInterlockedAnd64
360 FORCEINLINE
361 LONG64
_InlineInterlockedAnd64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)362 _InlineInterlockedAnd64(
363     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
364     _In_ LONG64 Value)
365 {
366     LONG64 Old, Prev, New;
367     for (Old = *Target; ; Old = Prev)
368     {
369         New = Old & Value;
370         Prev = _InterlockedCompareExchange64(Target, New, Old);
371         if (Prev == Old)
372             return New;
373     }
374 }
375 
376 #undef _InterlockedOr64
377 #define _InterlockedOr64 _InlineInterlockedOr64
378 FORCEINLINE
379 LONG64
_InlineInterlockedOr64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)380 _InlineInterlockedOr64(
381     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
382     _In_ LONG64 Value)
383 {
384     LONG64 Old, Prev, New;
385     for (Old = *Target; ; Old = Prev)
386     {
387         New = Old | Value;
388         Prev = _InterlockedCompareExchange64(Target, New, Old);
389         if (Prev == Old)
390             return New;
391     }
392 }
393 
394 #undef _InterlockedXor64
395 #define _InterlockedXor64 _InlineInterlockedXor64
396 FORCEINLINE
397 LONG64
_InlineInterlockedXor64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)398 _InlineInterlockedXor64(
399     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
400     _In_ LONG64 Value)
401 {
402     LONG64 Old, Prev, New;
403     for (Old = *Target; ; Old = Prev)
404     {
405         New = Old ^ Value;
406         Prev = _InterlockedCompareExchange64(Target, New, Old);
407         if (Prev == Old)
408             return New;
409     }
410 }
411 
412 #undef _InterlockedIncrement64
413 #define _InterlockedIncrement64 _InlineInterlockedIncrement64
414 FORCEINLINE
415 LONG64
_InlineInterlockedIncrement64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target)416 _InlineInterlockedIncrement64(
417     _Inout_ _Interlocked_operand_ volatile LONG64 *Target)
418 {
419     return _InterlockedAdd64(Target, 1);
420 }
421 
422 #undef _InterlockedDecrement64
423 #define _InterlockedDecrement64 _InlineInterlockedDecrement64
424 FORCEINLINE
425 LONG64
_InlineInterlockedDecrement64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target)426 _InlineInterlockedDecrement64(
427     _Inout_ _Interlocked_operand_ volatile LONG64 *Target)
428 {
429     return _InterlockedAdd64(Target, -1);
430 }
431 
432 #undef _InterlockedExchangePointer
433 #define _InterlockedExchangePointer _InlineInterlockedExchangePointer
434 FORCEINLINE
_Ret_writes_(_Inexpressible_ (Unknown))435 _Ret_writes_(_Inexpressible_(Unknown))
436 PVOID
437 _InterlockedExchangePointer(
438     _Inout_ _At_(*Destination, _Pre_writable_byte_size_(_Inexpressible_(Unknown))
439         _Post_writable_byte_size_(_Inexpressible_(Unknown)))
440         _Interlocked_operand_ volatile PVOID *Destination,
441     _In_opt_ PVOID Value)
442 {
443     return (PVOID)InterlockedExchange((volatile long *)Destination, (long)Value);
444 }
445 
446 #undef _InterlockedCompareExchangePointer
447 #define _InterlockedCompareExchangePointer _InlineInterlockedCompareExchangePointer
448 FORCEINLINE
_Ret_writes_(_Inexpressible_ (Unknown))449 _Ret_writes_(_Inexpressible_(Unknown))
450 PVOID
451 _InterlockedCompareExchangePointer(
452     _Inout_ _At_(*Destination, _Pre_writable_byte_size_(_Inexpressible_(Unknown))
453         _Post_writable_byte_size_(_Inexpressible_(Unknown)))
454         _Interlocked_operand_ volatile PVOID *Destination,
455     _In_opt_ PVOID ExChange,
456     _In_opt_ PVOID Comperand)
457 {
458     return (PVOID)InterlockedCompareExchange((volatile long *)Destination,
459                                              (long)ExChange,
460                                              (long)Comperand);
461 }
462 
463 #endif /* _M_IX86 */
464 
465 #ifdef _M_AMD64
466 
467 FORCEINLINE
468 LONG64
_InterlockedAdd64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Value)469 _InterlockedAdd64(
470     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
471     _In_ LONG64 Value)
472 
473 {
474     return _InterlockedExchangeAdd64(Target, Value) + Value;
475 }
476 
477 #endif /* _M_AMD64 */
478 
479 #ifdef _M_IA64
480 
481 #undef _InterlockedBitTestAndSet
482 #define _InterlockedBitTestAndSet InterlockedBitTestAndSet_Inline
483 FORCEINLINE
484 BOOLEAN
_InterlockedBitTestAndSet(_Inout_ _Interlocked_operand_ volatile LONG * Target,_In_ LONG Bit)485 _InterlockedBitTestAndSet(
486     _Inout_ _Interlocked_operand_ volatile LONG *Target,
487     _In_ LONG Bit)
488 {
489     ULONG Mask = 1 << (Bit & 31);
490     return (BOOLEAN)((InterlockedOr(&Target[Bit / 32], Mask) & Mask) != 0);
491 }
492 
493 #undef _InterlockedBitTestAndReset
494 #define _InterlockedBitTestAndReset InterlockedBitTestAndReset_Inline
495 FORCEINLINE
496 BOOLEAN
_InterlockedBitTestAndReset(_Inout_ _Interlocked_operand_ volatile LONG * Target,_In_ LONG Bit)497 _InterlockedBitTestAndReset(
498     _Inout_ _Interlocked_operand_ volatile LONG *Target,
499     _In_ LONG Bit)
500 {
501     ULONG Mask = 1 << (Bit & 31);
502     return (BOOLEAN)((InterlockedAnd(&Target[Bit / 32], ~Mask) & Mask) != 0);
503 }
504 
505 #undef _InterlockedBitTestAndSet64
506 #define _InterlockedBitTestAndSet64 InterlockedBitTestAndSet64_Inline
507 FORCEINLINE
508 BOOLEAN
_InterlockedBitTestAndSet64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Bit)509 _InterlockedBitTestAndSet64(
510     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
511     _In_ LONG64 Bit)
512 {
513     ULONG64 Mask = 1LL << (Bit & 63);
514     return (BOOLEAN)((InterlockedOr64(&Target[Bit / 64], Mask) & Mask) != 0);
515 }
516 
517 #undef _InterlockedBitTestAndReset64
518 #define _InterlockedBitTestAndReset64 InterlockedBitTestAndReset64_Inline
519 FORCEINLINE
520 BOOLEAN
_InterlockedBitTestAndReset64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Bit)521 _InterlockedBitTestAndReset64(
522     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
523     _In_ LONG64 Bit)
524 {
525     ULONG64 Mask = 1LL << (Bit & 63);
526     return (BOOLEAN)((InterlockedAnd64(&Target[Bit / 64], ~Mask) & Mask) != 0);
527 }
528 
529 #undef _InterlockedBitTestAndComplement
530 #define _InterlockedBitTestAndComplement InterlockedBitTestAndComplement_Inline
531 FORCEINLINE
532 BOOLEAN
_InterlockedBitTestAndComplement(_Inout_ _Interlocked_operand_ volatile LONG * Target,_In_ LONG Bit)533 _InterlockedBitTestAndComplement(
534     _Inout_ _Interlocked_operand_ volatile LONG *Target,
535     _In_ LONG Bit)
536 {
537     ULONG Mask = 1 << (Bit & 31);
538     return (BOOLEAN)((InterlockedXor(&Target[Bit / 32], Mask) & Mask) != 0);
539 }
540 
541 #undef _InterlockedBitTestAndComplement64
542 #define _InterlockedBitTestAndComplement64 InterlockedBitTestAndComplement64_Inline
543 FORCEINLINE
544 BOOLEAN
_InterlockedBitTestAndComplement64(_Inout_ _Interlocked_operand_ volatile LONG64 * Target,_In_ LONG64 Bit)545 _InterlockedBitTestAndComplement64(
546     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
547     _In_ LONG64 Bit)
548 {
549     ULONG64 Mask = 1LL << (Bit & 63);
550     return (BOOLEAN)((InterlockedXor64(&Target[Bit / 64], Mask) & Mask) != 0);
551 }
552 
553 #endif /* M_IA64 */
554 
555