1 /******************************************************************************
2 * INTERLOCKED Functions *
3 ******************************************************************************/
5 // Intrinsics (note: taken from our winnt.h)
10 static __inline__ BOOLEAN
11 InterlockedBitTestAndSet(IN LONG
volatile *Base
,
16 __asm__
__volatile__("lock "
19 :"=r" (OldBit
),"+m" (*Base
)
24 return (_InterlockedOr(Base
, 1 << Bit
) >> Bit
) & 1;
28 static __inline__ BOOLEAN
29 InterlockedBitTestAndReset(IN LONG
volatile *Base
,
34 __asm__
__volatile__("lock "
37 :"=r" (OldBit
),"+m" (*Base
)
42 return (_InterlockedAnd(Base
, ~(1 << Bit
)) >> Bit
) & 1;
48 #define BitScanForward _BitScanForward
49 #define BitScanReverse _BitScanReverse
50 #define BitTest _bittest
51 #define BitTestAndComplement _bittestandcomplement
52 #define BitTestAndSet _bittestandset
53 #define BitTestAndReset _bittestandreset
54 #define InterlockedBitTestAndSet _interlockedbittestandset
55 #define InterlockedBitTestAndReset _interlockedbittestandreset
58 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
59 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
62 #if !defined(__INTERLOCKED_DECLARED)
63 #define __INTERLOCKED_DECLARED
66 #if defined(NO_INTERLOCKED_INTRINSICS)
71 IN OUT LONG
volatile *Addend
);
77 IN OUT LONG
volatile *Addend
);
82 InterlockedCompareExchange(
83 IN OUT LONG
volatile *Destination
,
91 IN OUT LONG
volatile *Destination
,
97 InterlockedExchangeAdd(
98 IN OUT LONG
volatile *Addend
,
101 #else // !defined(NO_INTERLOCKED_INTRINSICS)
103 #define InterlockedExchange _InterlockedExchange
104 #define InterlockedIncrement _InterlockedIncrement
105 #define InterlockedDecrement _InterlockedDecrement
106 #define InterlockedExchangeAdd _InterlockedExchangeAdd
107 #define InterlockedCompareExchange _InterlockedCompareExchange
108 #define InterlockedOr _InterlockedOr
109 #define InterlockedAnd _InterlockedAnd
110 #define InterlockedXor _InterlockedXor
112 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
114 #endif // defined (_X86_)
116 #if !defined (_WIN64)
119 * InterlockedExchangePointer(
120 * IN OUT PVOID volatile *Target,
123 #define InterlockedExchangePointer(Target, Value) \
124 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
128 * InterlockedCompareExchangePointer(
129 * IN OUT PVOID *Destination,
131 * IN PVOID Comparand)
133 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
134 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
136 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
137 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
138 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
140 #endif // !defined (_WIN64)
142 #if defined (_M_AMD64)
144 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
145 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
146 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
147 #define InterlockedAnd _InterlockedAnd
148 #define InterlockedOr _InterlockedOr
149 #define InterlockedXor _InterlockedXor
150 #define InterlockedIncrement _InterlockedIncrement
151 #define InterlockedDecrement _InterlockedDecrement
152 #define InterlockedAdd _InterlockedAdd
153 #define InterlockedExchange _InterlockedExchange
154 #define InterlockedExchangeAdd _InterlockedExchangeAdd
155 #define InterlockedCompareExchange _InterlockedCompareExchange
156 #define InterlockedAnd64 _InterlockedAnd64
157 #define InterlockedOr64 _InterlockedOr64
158 #define InterlockedXor64 _InterlockedXor64
159 #define InterlockedIncrement64 _InterlockedIncrement64
160 #define InterlockedDecrement64 _InterlockedDecrement64
161 #define InterlockedAdd64 _InterlockedAdd64
162 #define InterlockedExchange64 _InterlockedExchange64
163 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
164 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
165 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
166 #define InterlockedExchangePointer _InterlockedExchangePointer
167 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
168 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
172 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
173 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
177 IN OUT LONG64
volatile *Addend
,
180 return InterlockedExchangeAdd64(Addend
, Value
) + Value
;
185 #endif /* !__INTERLOCKED_DECLARED */