44#pragma intrinsic(_InterlockedCompareExchange)
45#pragma intrinsic(_InterlockedCompareExchange16)
46#pragma intrinsic(_InterlockedCompareExchange64)
47#if LASS_COMPILER_VERSION >= 1500
48# pragma intrinsic(_InterlockedCompareExchange128)
50#pragma intrinsic(_InterlockedIncrement)
51#pragma intrinsic(_InterlockedIncrement16)
52#pragma intrinsic(_InterlockedIncrement64)
53#pragma intrinsic(_InterlockedDecrement)
54#pragma intrinsic(_InterlockedDecrement16)
55#pragma intrinsic(_InterlockedDecrement64)
56#pragma intrinsic(__ll_rshift)
60 bool lass_cas8(
volatile lass::num::Tuint8*, lass::num::Tuint8, lass::num::Tuint8);
61 void lass_inc8(
volatile lass::num::Tuint8*);
62 void lass_dec8(
volatile lass::num::Tuint8*);
63 bool lass_dcas8(
volatile lass::num::Tuint8*, lass::num::Tuint8, lass::num::Tuint8, lass::num::Tuint8, lass::num::Tuint8);
64 bool lass_dcas16(
volatile lass::num::Tuint16*, lass::num::Tuint16, lass::num::Tuint16, lass::num::Tuint16, lass::num::Tuint16);
65 bool lass_dcas32(
volatile lass::num::Tuint32*, lass::num::Tuint32, lass::num::Tuint32, lass::num::Tuint32, lass::num::Tuint32);
66 bool lass_dcas64(
volatile lass::num::Tuint64*, lass::num::Tuint64, lass::num::Tuint64, lass::num::Tuint64, lass::num::Tuint64);
77struct AtomicOperations<1>
79 template <
typename T>
inline
80 static bool LASS_CALL compareAndSwap(
volatile T& dest, T expectedValue, T newValue)
82 return lass_cas8(
reinterpret_cast<volatile num::Tuint8*
>(&dest),
83 *
reinterpret_cast<num::Tuint8*
>(&newValue), *
reinterpret_cast<num::Tuint8*
>(&expectedValue));
86 template <
typename T1,
typename T2>
inline
87 static bool LASS_CALL compareAndSwap(
88 volatile T1& dest1, T1 expected1, T2 expected2, T1 new1, T2 new2)
91 reinterpret_cast<volatile num::Tuint8*
>(&dest1),
92 *
reinterpret_cast<num::Tuint8*
>(&new1), *
reinterpret_cast<num::Tuint8*
>(&new2),
93 *
reinterpret_cast<num::Tuint8*
>(&expected1), *
reinterpret_cast<num::Tuint8*
>(&expected2));
96 template <
typename T>
inline
97 static void LASS_CALL increment(
volatile T& value)
99 lass_inc8(
reinterpret_cast<volatile num::Tuint8*
>(&value));
102 template <
typename T>
inline
103 static void LASS_CALL decrement(
volatile T& value)
105 lass_dec8(
reinterpret_cast<volatile num::Tuint8*
>(&value));
112struct AtomicOperations<2>
114 template <
typename T>
inline
115 static bool LASS_CALL compareAndSwap(
volatile T& dest, T expectedValue, T newValue)
117 const short expected = *
reinterpret_cast<short*
>(&expectedValue);
118 return _InterlockedCompareExchange16(
reinterpret_cast<volatile short*
>(&dest),
119 *
reinterpret_cast<short*
>(&newValue), expected) == expected;
122 template <
typename T1,
typename T2>
inline
123 static bool LASS_CALL compareAndSwap(
124 volatile T1& dest1, T1 expected1, T2 expected2, T1 new1, T2 new2)
127 reinterpret_cast<volatile num::Tuint16*
>(&dest1),
128 *
reinterpret_cast<num::Tuint16*
>(&new1), *
reinterpret_cast<num::Tuint16*
>(&new2),
129 *
reinterpret_cast<num::Tuint16*
>(&expected1), *
reinterpret_cast<num::Tuint16*
>(&expected2));
132 template <
typename T>
inline
133 static void LASS_CALL increment(
volatile T& value)
135 _InterlockedIncrement16(
reinterpret_cast<volatile short*
>(&value));
138 template <
typename T>
inline
139 static void LASS_CALL decrement(
volatile T& value)
141 _InterlockedDecrement16(
reinterpret_cast<volatile short*
>(&value));
148struct AtomicOperations<4>
150 template <
typename T>
inline
151 static bool LASS_CALL compareAndSwap(
volatile T& dest, T expectedValue, T newValue)
153 const long expected = *
reinterpret_cast<long*
>(&expectedValue);
154 return _InterlockedCompareExchange(
reinterpret_cast<volatile long*
>(&dest),
155 *
reinterpret_cast<long*
>(&newValue), expected) == expected;
158 template <
typename T1,
typename T2>
inline
159 static bool LASS_CALL compareAndSwap(
160 volatile T1& dest1, T1 expected1, T2 expected2, T1 new1, T2 new2)
163 reinterpret_cast<volatile num::Tuint32*
>(&dest1),
164 *
reinterpret_cast<num::Tuint32*
>(&new1), *
reinterpret_cast<num::Tuint32*
>(&new2),
165 *
reinterpret_cast<num::Tuint32*
>(&expected1), *
reinterpret_cast<num::Tuint32*
>(&expected2));
168 template <
typename T>
inline
169 static void LASS_CALL increment(
volatile T& value)
171 _InterlockedIncrement(
reinterpret_cast<volatile long*
>(&value));
174 template <
typename T>
inline
175 static void LASS_CALL decrement(
volatile T& value)
177 _InterlockedDecrement(
reinterpret_cast<volatile long*
>(&value));
184struct AtomicOperations<8>
186 template <
typename T>
inline
187 static bool LASS_CALL compareAndSwap(
volatile T& dest, T expectedValue, T newValue)
189 const __int64 expected = *
reinterpret_cast<__int64*
>(&expectedValue);
190 return _InterlockedCompareExchange64(
reinterpret_cast<volatile __int64*
>(&dest),
191 *
reinterpret_cast<__int64*
>(&newValue), expected) == expected;
194 template <
typename T1,
typename T2>
inline
195 static bool LASS_CALL compareAndSwap(
196 volatile T1& dest1, T1 expected1, T2 expected2, T1 new1, T2 new2)
198 LASS_ASSERT((
reinterpret_cast<num::Tuint64
>(&dest1) & 0xf) == 0);
199#if LASS_COMPILER_VERSION >= 1500
200 __int64 expected[2] = { *
reinterpret_cast<__int64*
>(&expected1), *
reinterpret_cast<__int64*
>(&expected2) };
201 return _InterlockedCompareExchange128(
202 reinterpret_cast<volatile __int64*
>(&dest1),
203 *
reinterpret_cast<__int64*
>(&new2), *
reinterpret_cast<__int64*
>(&new1),
207 reinterpret_cast<volatile num::Tuint64*
>(&dest1),
208 *
reinterpret_cast<num::Tuint64*
>(&new1), *
reinterpret_cast<num::Tuint64*
>(&new2),
209 *
reinterpret_cast<num::Tuint64*
>(&expected1), *
reinterpret_cast<num::Tuint64*
>(&expected2));
213 template <
typename T>
inline
214 static void LASS_CALL increment(
volatile T& value)
216 _InterlockedIncrement64(
reinterpret_cast<volatile __int64*
>(&value));
219 template <
typename T>
inline
220 static void LASS_CALL decrement(
volatile T& value)
222 _InterlockedDecrement64(
reinterpret_cast<volatile __int64*
>(&value));
general utility, debug facilities, ...
Library for Assembled Shared Sources.