xref: /reactos/sdk/include/xdk/interlocked.h (revision c2c66aff)
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 FORCEINLINE
305 LONG64
306 _InterlockedExchange64(
307     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
308     _In_ LONG64 Value)
309 {
310     LONG64 Old, Prev;
311     for (Old = *Target; ; Old = Prev)
312     {
313         Prev = _InterlockedCompareExchange64(Target, Value, Old);
314         if (Prev == Old)
315             return Prev;
316     }
317 }
318 
319 FORCEINLINE
320 LONG64
321 _InterlockedAdd64(
322     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
323     _In_ LONG64 Value)
324 {
325     LONG64 Old, Prev, New;
326     for (Old = *Target; ; Old = Prev)
327     {
328         New = Old + Value;
329         Prev = _InterlockedCompareExchange64(Target, New, Old);
330         if (Prev == Old)
331             return New;
332     }
333 }
334 
335 FORCEINLINE
336 LONG64
337 _InterlockedExchangeAdd64 (
338     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
339     _In_ LONG64 Value
340     )
341 {
342     LONG64 Old, Prev, New;
343     for (Old = *Target; ; Old = Prev)
344     {
345         New = Old + Value;
346         Prev = _InterlockedCompareExchange64(Target, New, Old);
347         if (Prev == Old)
348             return Prev;
349     }
350 }
351 
352 FORCEINLINE
353 LONG64
354 _InterlockedAnd64(
355     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
356     _In_ LONG64 Value)
357 {
358     LONG64 Old, Prev, New;
359     for (Old = *Target; ; Old = Prev)
360     {
361         New = Old & Value;
362         Prev = _InterlockedCompareExchange64(Target, New, Old);
363         if (Prev == Old)
364             return New;
365     }
366 }
367 
368 FORCEINLINE
369 LONG64
370 _InterlockedOr64(
371     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
372     _In_ LONG64 Value)
373 {
374     LONG64 Old, Prev, New;
375     for (Old = *Target; ; Old = Prev)
376     {
377         New = Old | Value;
378         Prev = _InterlockedCompareExchange64(Target, New, Old);
379         if (Prev == Old)
380             return New;
381     }
382 }
383 
384 FORCEINLINE
385 LONG64
386 _InterlockedXor64(
387     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
388     _In_ LONG64 Value)
389 {
390     LONG64 Old, Prev, New;
391     for (Old = *Target; ; Old = Prev)
392     {
393         New = Old ^ Value;
394         Prev = _InterlockedCompareExchange64(Target, New, Old);
395         if (Prev == Old)
396             return New;
397     }
398 }
399 
400 FORCEINLINE
401 LONG64
402 _InterlockedIncrement64(
403     _Inout_ _Interlocked_operand_ volatile LONG64 *Target)
404 {
405     return _InterlockedAdd64(Target, 1);
406 }
407 
408 FORCEINLINE
409 LONG64
410 _InterlockedDecrement64(
411     _Inout_ _Interlocked_operand_ volatile LONG64 *Target)
412 {
413     return _InterlockedAdd64(Target, -1);
414 }
415 
416 #undef _InterlockedExchangePointer
417 #define _InterlockedExchangePointer _InlineInterlockedExchangePointer
418 FORCEINLINE
419 _Ret_writes_(_Inexpressible_(Unknown))
420 PVOID
421 _InterlockedExchangePointer(
422     _Inout_ _At_(*Destination, _Pre_writable_byte_size_(_Inexpressible_(Unknown))
423         _Post_writable_byte_size_(_Inexpressible_(Unknown)))
424         _Interlocked_operand_ volatile PVOID *Destination,
425     _In_opt_ PVOID Value)
426 {
427     return (PVOID)InterlockedExchange((volatile long *)Destination, (long)Value);
428 }
429 
430 #undef _InterlockedCompareExchangePointer
431 #define _InterlockedCompareExchangePointer _InlineInterlockedCompareExchangePointer
432 FORCEINLINE
433 _Ret_writes_(_Inexpressible_(Unknown))
434 PVOID
435 _InterlockedCompareExchangePointer(
436     _Inout_ _At_(*Destination, _Pre_writable_byte_size_(_Inexpressible_(Unknown))
437         _Post_writable_byte_size_(_Inexpressible_(Unknown)))
438         _Interlocked_operand_ volatile PVOID *Destination,
439     _In_opt_ PVOID ExChange,
440     _In_opt_ PVOID Comperand)
441 {
442     return (PVOID)InterlockedCompareExchange((volatile long *)Destination,
443                                              (long)ExChange,
444                                              (long)Comperand);
445 }
446 
447 #endif /* _M_IX86 */
448 
449 #ifdef _M_AMD64
450 
451 FORCEINLINE
452 LONG64
453 _InterlockedAdd64(
454     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
455     _In_ LONG64 Value)
456 
457 {
458     return _InterlockedExchangeAdd64(Target, Value) + Value;
459 }
460 
461 #endif /* _M_AMD64 */
462 
463 #ifdef _M_IA64
464 
465 #undef _InterlockedBitTestAndSet
466 #define _InterlockedBitTestAndSet InterlockedBitTestAndSet_Inline
467 FORCEINLINE
468 BOOLEAN
469 _InterlockedBitTestAndSet(
470     _Inout_ _Interlocked_operand_ volatile LONG *Target,
471     _In_ LONG Bit)
472 {
473     ULONG Mask = 1 << (Bit & 31);
474     return (BOOLEAN)((InterlockedOr(&Target[Bit / 32], Mask) & Mask) != 0);
475 }
476 
477 #undef _InterlockedBitTestAndReset
478 #define _InterlockedBitTestAndReset InterlockedBitTestAndReset_Inline
479 FORCEINLINE
480 BOOLEAN
481 _InterlockedBitTestAndReset(
482     _Inout_ _Interlocked_operand_ volatile LONG *Target,
483     _In_ LONG Bit)
484 {
485     ULONG Mask = 1 << (Bit & 31);
486     return (BOOLEAN)((InterlockedAnd(&Target[Bit / 32], ~Mask) & Mask) != 0);
487 }
488 
489 #undef _InterlockedBitTestAndSet64
490 #define _InterlockedBitTestAndSet64 InterlockedBitTestAndSet64_Inline
491 FORCEINLINE
492 BOOLEAN
493 _InterlockedBitTestAndSet64(
494     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
495     _In_ LONG64 Bit)
496 {
497     ULONG64 Mask = 1LL << (Bit & 63);
498     return (BOOLEAN)((InterlockedOr64(&Target[Bit / 64], Mask) & Mask) != 0);
499 }
500 
501 #undef _InterlockedBitTestAndReset64
502 #define _InterlockedBitTestAndReset64 InterlockedBitTestAndReset64_Inline
503 FORCEINLINE
504 BOOLEAN
505 _InterlockedBitTestAndReset64(
506     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
507     _In_ LONG64 Bit)
508 {
509     ULONG64 Mask = 1LL << (Bit & 63);
510     return (BOOLEAN)((InterlockedAnd64(&Target[Bit / 64], ~Mask) & Mask) != 0);
511 }
512 
513 #undef _InterlockedBitTestAndComplement
514 #define _InterlockedBitTestAndComplement InterlockedBitTestAndComplement_Inline
515 FORCEINLINE
516 BOOLEAN
517 _InterlockedBitTestAndComplement(
518     _Inout_ _Interlocked_operand_ volatile LONG *Target,
519     _In_ LONG Bit)
520 {
521     ULONG Mask = 1 << (Bit & 31);
522     return (BOOLEAN)((InterlockedXor(&Target[Bit / 32], Mask) & Mask) != 0);
523 }
524 
525 #undef _InterlockedBitTestAndComplement64
526 #define _InterlockedBitTestAndComplement64 InterlockedBitTestAndComplement64_Inline
527 FORCEINLINE
528 BOOLEAN
529 _InterlockedBitTestAndComplement64(
530     _Inout_ _Interlocked_operand_ volatile LONG64 *Target,
531     _In_ LONG64 Bit)
532 {
533     ULONG64 Mask = 1LL << (Bit & 63);
534     return (BOOLEAN)((InterlockedXor64(&Target[Bit / 64], Mask) & Mask) != 0);
535 }
536 
537 #endif /* M_IA64 */
538 
539