Sync with trunk revision 64099.
[reactos.git] / include / xdk / interlocked.h
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 #define InterlockedBitTestAndSet _interlockedbittestandset
12 #define InterlockedBitTestAndReset _interlockedbittestandreset
13
14 #ifdef _M_AMD64
15 #define BitScanForward64 _BitScanForward64
16 #define BitScanReverse64 _BitScanReverse64
17 #define BitTest64 _bittest64
18 #define BitTestAndComplement64 _bittestandcomplement64
19 #define BitTestAndSet64 _bittestandset64
20 #define BitTestAndReset64 _bittestandreset64
21 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
22 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
23 #endif
24
25 #if !defined(__INTERLOCKED_DECLARED)
26 #define __INTERLOCKED_DECLARED
27
28 #if defined (_X86_)
29 #if defined(NO_INTERLOCKED_INTRINSICS)
30 NTKERNELAPI
31 LONG
32 FASTCALL
33 InterlockedIncrement(
34 _Inout_ _Interlocked_operand_ LONG volatile *Addend);
35
36 NTKERNELAPI
37 LONG
38 FASTCALL
39 InterlockedDecrement(
40 _Inout_ _Interlocked_operand_ LONG volatile *Addend);
41
42 NTKERNELAPI
43 LONG
44 FASTCALL
45 InterlockedCompareExchange(
46 _Inout_ _Interlocked_operand_ LONG volatile *Destination,
47 _In_ LONG Exchange,
48 _In_ LONG Comparand);
49
50 NTKERNELAPI
51 LONG
52 FASTCALL
53 InterlockedExchange(
54 _Inout_ _Interlocked_operand_ LONG volatile *Destination,
55 _In_ LONG Value);
56
57 NTKERNELAPI
58 LONG
59 FASTCALL
60 InterlockedExchangeAdd(
61 _Inout_ _Interlocked_operand_ LONG volatile *Addend,
62 _In_ LONG Value);
63
64 #else /* !defined(NO_INTERLOCKED_INTRINSICS) */
65
66 #define InterlockedExchange _InterlockedExchange
67 #define InterlockedIncrement _InterlockedIncrement
68 #define InterlockedDecrement _InterlockedDecrement
69 #define InterlockedExchangeAdd _InterlockedExchangeAdd
70 #define InterlockedCompareExchange _InterlockedCompareExchange
71 #define InterlockedOr _InterlockedOr
72 #define InterlockedAnd _InterlockedAnd
73 #define InterlockedXor _InterlockedXor
74
75 #endif /* !defined(NO_INTERLOCKED_INTRINSICS) */
76
77 #endif /* defined (_X86_) */
78
79 #if !defined (_WIN64)
80 /*
81 * PVOID
82 * InterlockedExchangePointer(
83 * IN OUT PVOID volatile *Target,
84 * IN PVOID Value)
85 */
86 #define InterlockedExchangePointer(Target, Value) \
87 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
88
89 /*
90 * PVOID
91 * InterlockedCompareExchangePointer(
92 * IN OUT PVOID *Destination,
93 * IN PVOID Exchange,
94 * IN PVOID Comparand)
95 */
96 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
97 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
98
99 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
100 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
101 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
102
103 #endif // !defined (_WIN64)
104
105 #if defined (_M_AMD64)
106
107 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
108 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
109 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
110 #define InterlockedAnd _InterlockedAnd
111 #define InterlockedOr _InterlockedOr
112 #define InterlockedXor _InterlockedXor
113 #define InterlockedIncrement _InterlockedIncrement
114 #define InterlockedDecrement _InterlockedDecrement
115 #define InterlockedAdd _InterlockedAdd
116 #define InterlockedExchange _InterlockedExchange
117 #define InterlockedExchangeAdd _InterlockedExchangeAdd
118 #define InterlockedCompareExchange _InterlockedCompareExchange
119 #define InterlockedAnd64 _InterlockedAnd64
120 #define InterlockedOr64 _InterlockedOr64
121 #define InterlockedXor64 _InterlockedXor64
122 #define InterlockedIncrement64 _InterlockedIncrement64
123 #define InterlockedDecrement64 _InterlockedDecrement64
124 #define InterlockedAdd64 _InterlockedAdd64
125 #define InterlockedExchange64 _InterlockedExchange64
126 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
127 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
128 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
129 #define InterlockedExchangePointer _InterlockedExchangePointer
130 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
131 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
132
133 #endif // _M_AMD64
134
135 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
136 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
137 FORCEINLINE
138 LONG64
139 InterlockedAdd64(
140 _Inout_ _Interlocked_operand_ LONG64 volatile *Addend,
141 _In_ LONG64 Value)
142 {
143 return InterlockedExchangeAdd64(Addend, Value) + Value;
144 }
145 //#endif
146 #endif
147
148 #endif /* !__INTERLOCKED_DECLARED */
149
150