1 /******************************************************************************
2 * INTERLOCKED Functions *
3 ******************************************************************************/
5 // Intrinsics (note: taken from our winnt.h)
10 static __inline__ BOOLEAN
11 InterlockedBitTestAndSet(
12 IN LONG
volatile *Base
,
17 __asm__
__volatile__("lock "
20 :"=r" (OldBit
),"+m" (*Base
)
25 return (_InterlockedOr(Base
, 1 << Bit
) >> Bit
) & 1;
29 static __inline__ BOOLEAN
30 InterlockedBitTestAndReset(
31 IN LONG
volatile *Base
,
36 __asm__
__volatile__("lock "
39 :"=r" (OldBit
),"+m" (*Base
)
44 return (_InterlockedAnd(Base
, ~(1 << Bit
)) >> Bit
) & 1;
48 #endif /* defined(__GNUC__) */
50 #define BitScanForward _BitScanForward
51 #define BitScanReverse _BitScanReverse
52 #define BitTest _bittest
53 #define BitTestAndComplement _bittestandcomplement
54 #define BitTestAndSet _bittestandset
55 #define BitTestAndReset _bittestandreset
56 #define InterlockedBitTestAndSet _interlockedbittestandset
57 #define InterlockedBitTestAndReset _interlockedbittestandreset
60 #define BitTest64 _bittest64
61 #define BitTestAndComplement64 _bittestandcomplement64
62 #define BitTestAndSet64 _bittestandset64
63 #define BitTestAndReset64 _bittestandreset64
64 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
65 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
68 #if !defined(__INTERLOCKED_DECLARED)
69 #define __INTERLOCKED_DECLARED
72 #if defined(NO_INTERLOCKED_INTRINSICS)
77 IN OUT LONG
volatile *Addend
);
83 IN OUT LONG
volatile *Addend
);
88 InterlockedCompareExchange(
89 IN OUT LONG
volatile *Destination
,
97 IN OUT LONG
volatile *Destination
,
103 InterlockedExchangeAdd(
104 IN OUT LONG
volatile *Addend
,
107 #else /* !defined(NO_INTERLOCKED_INTRINSICS) */
109 #define InterlockedExchange _InterlockedExchange
110 #define InterlockedIncrement _InterlockedIncrement
111 #define InterlockedDecrement _InterlockedDecrement
112 #define InterlockedExchangeAdd _InterlockedExchangeAdd
113 #define InterlockedCompareExchange _InterlockedCompareExchange
114 #define InterlockedOr _InterlockedOr
115 #define InterlockedAnd _InterlockedAnd
116 #define InterlockedXor _InterlockedXor
118 #endif /* !defined(NO_INTERLOCKED_INTRINSICS) */
120 #endif /* defined (_X86_) */
122 #if !defined (_WIN64)
125 * InterlockedExchangePointer(
126 * IN OUT PVOID volatile *Target,
129 #define InterlockedExchangePointer(Target, Value) \
130 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
134 * InterlockedCompareExchangePointer(
135 * IN OUT PVOID *Destination,
137 * IN PVOID Comparand)
139 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
140 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
142 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
143 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
144 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
146 #endif // !defined (_WIN64)
148 #if defined (_M_AMD64)
150 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
151 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
152 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
153 #define InterlockedAnd _InterlockedAnd
154 #define InterlockedOr _InterlockedOr
155 #define InterlockedXor _InterlockedXor
156 #define InterlockedIncrement _InterlockedIncrement
157 #define InterlockedDecrement _InterlockedDecrement
158 #define InterlockedAdd _InterlockedAdd
159 #define InterlockedExchange _InterlockedExchange
160 #define InterlockedExchangeAdd _InterlockedExchangeAdd
161 #define InterlockedCompareExchange _InterlockedCompareExchange
162 #define InterlockedAnd64 _InterlockedAnd64
163 #define InterlockedOr64 _InterlockedOr64
164 #define InterlockedXor64 _InterlockedXor64
165 #define InterlockedIncrement64 _InterlockedIncrement64
166 #define InterlockedDecrement64 _InterlockedDecrement64
167 #define InterlockedAdd64 _InterlockedAdd64
168 #define InterlockedExchange64 _InterlockedExchange64
169 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
170 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
171 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
172 #define InterlockedExchangePointer _InterlockedExchangePointer
173 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
174 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
178 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
179 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
183 IN OUT LONG64
volatile *Addend
,
186 return InterlockedExchangeAdd64(Addend
, Value
) + Value
;
191 #endif /* !__INTERLOCKED_DECLARED */