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 InterlockedBitTestAndSet64 _interlockedbittestandset64
61 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
64 #if !defined(__INTERLOCKED_DECLARED)
65 #define __INTERLOCKED_DECLARED
68 #if defined(NO_INTERLOCKED_INTRINSICS)
73 IN OUT LONG
volatile *Addend
);
79 IN OUT LONG
volatile *Addend
);
84 InterlockedCompareExchange(
85 IN OUT LONG
volatile *Destination
,
93 IN OUT LONG
volatile *Destination
,
99 InterlockedExchangeAdd(
100 IN OUT LONG
volatile *Addend
,
103 #else /* !defined(NO_INTERLOCKED_INTRINSICS) */
105 #define InterlockedExchange _InterlockedExchange
106 #define InterlockedIncrement _InterlockedIncrement
107 #define InterlockedDecrement _InterlockedDecrement
108 #define InterlockedExchangeAdd _InterlockedExchangeAdd
109 #define InterlockedCompareExchange _InterlockedCompareExchange
110 #define InterlockedOr _InterlockedOr
111 #define InterlockedAnd _InterlockedAnd
112 #define InterlockedXor _InterlockedXor
114 #endif /* !defined(NO_INTERLOCKED_INTRINSICS) */
116 #endif /* defined (_X86_) */
118 #if !defined (_WIN64)
121 * InterlockedExchangePointer(
122 * IN OUT PVOID volatile *Target,
125 #define InterlockedExchangePointer(Target, Value) \
126 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
130 * InterlockedCompareExchangePointer(
131 * IN OUT PVOID *Destination,
133 * IN PVOID Comparand)
135 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
136 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
138 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
139 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
140 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
142 #endif // !defined (_WIN64)
144 #if defined (_M_AMD64)
146 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
147 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
148 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
149 #define InterlockedAnd _InterlockedAnd
150 #define InterlockedOr _InterlockedOr
151 #define InterlockedXor _InterlockedXor
152 #define InterlockedIncrement _InterlockedIncrement
153 #define InterlockedDecrement _InterlockedDecrement
154 #define InterlockedAdd _InterlockedAdd
155 #define InterlockedExchange _InterlockedExchange
156 #define InterlockedExchangeAdd _InterlockedExchangeAdd
157 #define InterlockedCompareExchange _InterlockedCompareExchange
158 #define InterlockedAnd64 _InterlockedAnd64
159 #define InterlockedOr64 _InterlockedOr64
160 #define InterlockedXor64 _InterlockedXor64
161 #define InterlockedIncrement64 _InterlockedIncrement64
162 #define InterlockedDecrement64 _InterlockedDecrement64
163 #define InterlockedAdd64 _InterlockedAdd64
164 #define InterlockedExchange64 _InterlockedExchange64
165 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
166 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
167 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
168 #define InterlockedExchangePointer _InterlockedExchangePointer
169 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
170 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
174 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
175 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
179 IN OUT LONG64
volatile *Addend
,
182 return InterlockedExchangeAdd64(Addend
, Value
) + Value
;
187 #endif /* !__INTERLOCKED_DECLARED */