1 #ifndef BOOST_DETAIL_ATOMIC_GENERIC_CAS_HPP 2 #define BOOST_DETAIL_ATOMIC_GENERIC_CAS_HPP 14 #include <boost/atomic/detail/builder.hpp> 22 namespace boost {
namespace detail {
namespace atomic {
24 fenced_compare_exchange_strong_32(
volatile int32_t *ptr, int32_t expected, int32_t desired)
26 return __sync_val_compare_and_swap_4(ptr, expected, desired);
28 #define BOOST_ATOMIC_HAVE_CAS32 1 30 #if defined(__amd64__) || defined(__i686__) 32 fenced_compare_exchange_strong_64(int64_t *ptr, int64_t expected, int64_t desired)
34 return __sync_val_compare_and_swap_8(ptr, expected, desired);
36 #define BOOST_ATOMIC_HAVE_CAS64 1 40 #elif defined(__ICL) || defined(_MSC_VER) 47 namespace boost {
namespace detail {
namespace atomic {
49 fenced_compare_exchange_strong(int32_t *ptr, int32_t expected, int32_t desired)
51 return _InterlockedCompareExchange(reinterpret_cast<volatile long*>(ptr), desired, expected);
53 #define BOOST_ATOMIC_HAVE_CAS32 1 56 fenced_compare_exchange_strong(int64_t *ptr, int64_t expected, int64_t desired)
58 return _InterlockedCompareExchange64(ptr, desired, expected);
60 #define BOOST_ATOMIC_HAVE_CAS64 1 64 #elif (defined(__ICC) || defined(__ECC)) 65 namespace boost {
namespace detail {
namespace atomic {
67 fenced_compare_exchange_strong_32(int32_t *ptr, int32_t expected, int32_t desired)
69 return _InterlockedCompareExchange((
void*)ptr, desired, expected);
71 #define BOOST_ATOMIC_HAVE_CAS32 1 74 fenced_compare_exchange_strong(int64_t *ptr, int64_t expected, int64_t desired)
76 return cas64<int>(ptr, expected, desired);
78 #define BOOST_ATOMIC_HAVE_CAS64 1 79 #elif defined(__ECC) //IA-64 version 81 fenced_compare_exchange_strong(int64_t *ptr, int64_t expected, int64_t desired)
83 return _InterlockedCompareExchange64((
void*)ptr, desired, expected);
85 #define BOOST_ATOMIC_HAVE_CAS64 1 89 #elif (defined(__SUNPRO_CC) && defined(__sparc)) 90 #include <sys/atomic.h> 91 namespace boost {
namespace detail {
namespace atomic {
93 fenced_compare_exchange_strong_32(int32_t *ptr, int32_t expected, int32_t desired)
95 return atomic_cas_32((
volatile unsigned int*)ptr, expected, desired);
97 #define BOOST_ATOMIC_HAVE_CAS32 1 100 static inline int64_t
101 fenced_compare_exchange_strong_64(int64_t *ptr, int64_t expected, int64_t desired)
103 return atomic_cas_64((
volatile unsigned long long*)ptr, expected, desired);
105 #define BOOST_ATOMIC_HAVE_CAS64 1 110 namespace boost {
namespace detail {
namespace atomic {
112 #ifdef BOOST_ATOMIC_HAVE_CAS32 114 class atomic_generic_cas32 {
116 typedef atomic_generic_cas32 this_type;
118 explicit atomic_generic_cas32(T v) : i((int32_t)v) {}
119 atomic_generic_cas32() {}
123 do { }
while(!const_cast<this_type *>(
this)->compare_exchange_weak(expected, expected, order,
memory_order_relaxed));
130 bool compare_exchange_strong(
137 found=(T)fenced_compare_exchange_strong_32(&i, (int32_t)expected, (int32_t)desired);
138 bool success=(found==expected);
142 bool compare_exchange_weak(
148 return compare_exchange_strong(expected, desired, success_order, failure_order);
157 bool is_lock_free(
void)
const volatile {
return true;}
158 typedef T integral_type;
164 class platform_atomic_integral<T, 4> :
public build_atomic_from_exchange<atomic_generic_cas32<T> > {
166 typedef build_atomic_from_exchange<atomic_generic_cas32<T> > super;
167 explicit platform_atomic_integral(T v) : super(v) {}
168 platform_atomic_integral(
void) {}
172 class platform_atomic_integral<T, 1>:
public build_atomic_from_larger_type<atomic_generic_cas32<int32_t>, T> {
174 typedef build_atomic_from_larger_type<atomic_generic_cas32<int32_t>, T> super;
176 explicit platform_atomic_integral(T v) : super(v) {}
177 platform_atomic_integral(
void) {}
181 class platform_atomic_integral<T, 2>:
public build_atomic_from_larger_type<atomic_generic_cas32<int32_t>, T> {
183 typedef build_atomic_from_larger_type<atomic_generic_cas32<int32_t>, T> super;
185 explicit platform_atomic_integral(T v) : super(v) {}
186 platform_atomic_integral(
void) {}