16 template<
class T>
class DtAtomicScalar
32 void operator= (
const DtAtomicScalar<T> &cousin)
47 bool cas (
const T &old,
const T &nu)
50 return _InterlockedCompareExchange16((SHORT*)&
mField, static_cast<SHORT>(nu), static_cast<SHORT>(old)) ==
static_cast<SHORT
>(old);
52 else if (
sizeof(T)==4)
54 return _InterlockedCompareExchange((LONG*)&
mField, static_cast<LONG>(nu), static_cast<LONG>(old)) ==
static_cast<LONG
>(old);
56 else if (
sizeof(T)==8) {
57 return _InterlockedCompareExchange64((LONGLONG*)&
mField, static_cast<LONGLONG>(nu), static_cast<LONGLONG>(old)) ==
static_cast<LONGLONG
>(old);
60 ASSERT_PREDICATE(
false&&
"AtomicScalar::cas: Only 16, 32, and 64 bit scalars supported in win32.");
68 return _InterlockedIncrement16((SHORT*)&
mField);
69 }
else if (
sizeof(T)==4) {
70 return InterlockedIncrement((LONG*)&
mField);
71 }
else if (
sizeof(T)==8) {
72 return InterlockedIncrement64((LONGLONG*)&
mField);
74 ASSERT_PREDICATE(
false&&
"AtomicScalar::operator++(prefix): Only 16, 32, and 64 bit scalars supported in win32.");
82 return InterlockedDecrement16((SHORT*)&
mField);
83 }
else if (
sizeof(T)==4) {
84 return InterlockedDecrement((LONG*)&
mField);
85 }
else if (
sizeof(T)==8) {
86 return InterlockedDecrement64((LONGLONG*)&
mField);
88 ASSERT_PREDICATE(
false&&
"AtomicScalar::operator--(prefix): Only 16, 32, and 64 bit scalars supported in win32.");
96 return _InterlockedIncrement16((SHORT*)&
mField)-1;
97 }
else if (
sizeof(T)==4) {
98 return InterlockedIncrement((LONG*)&
mField)-1;
99 }
else if (
sizeof(T)==8) {
100 return InterlockedIncrement64((LONGLONG*)&
mField)-1;
102 ASSERT_PREDICATE(
false&&
"AtomicScalar::operator++(postfix): Only 16, 32, and 64 bit scalars supported in win32.");
110 return InterlockedDecrement16((SHORT*)&
mField)+1;
111 }
else if (
sizeof(T)==4) {
112 return InterlockedDecrement((LONG*)&
mField)+1;
113 }
else if (
sizeof(T)==8) {
114 return InterlockedDecrement64((LONGLONG*)&
mField)+1;
116 ASSERT_PREDICATE(
false&&
"AtomicScalar::operator--(postfix): Only 16, 32, and 64 bit scalars supported in win32.");
151 void set (
const T &v)
156 bool cas (
const T &old,
const T &nu)
158 return __sync_bool_compare_and_swap (&
mField, old, nu);
163 __sync_add_and_fetch (&
mField, 1);
168 __sync_add_and_fetch (&
mField, -1);
173 __sync_fetch_and_add (&
mField, 1);
178 __sync_fetch_and_add (&
mField, -1);