42 |
42 |
43 template<size_t byte_size> |
43 template<size_t byte_size> |
44 struct Atomic::PlatformAdd |
44 struct Atomic::PlatformAdd |
45 : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> > |
45 : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> > |
46 { |
46 { |
47 template<typename I, typename D> |
47 template<typename D, typename I> |
48 D add_and_fetch(I add_value, D volatile* dest, atomic_memory_order order) const; |
48 D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const; |
49 }; |
49 }; |
50 |
50 |
51 // Not using add_using_helper; see comment for cmpxchg. |
51 // Not using add_using_helper; see comment for cmpxchg. |
52 template<> |
52 template<> |
53 template<typename I, typename D> |
53 template<typename D, typename I> |
54 inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest, |
54 inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value, |
55 atomic_memory_order order) const { |
55 atomic_memory_order order) const { |
56 STATIC_ASSERT(4 == sizeof(I)); |
56 STATIC_ASSERT(4 == sizeof(I)); |
57 STATIC_ASSERT(4 == sizeof(D)); |
57 STATIC_ASSERT(4 == sizeof(D)); |
58 return PrimitiveConversions::cast<D>( |
58 return PrimitiveConversions::cast<D>( |
59 _Atomic_add(PrimitiveConversions::cast<int32_t>(add_value), |
59 _Atomic_add(PrimitiveConversions::cast<int32_t>(add_value), |
60 reinterpret_cast<int32_t volatile*>(dest))); |
60 reinterpret_cast<int32_t volatile*>(dest))); |
61 } |
61 } |
62 |
62 |
63 // Not using add_using_helper; see comment for cmpxchg. |
63 // Not using add_using_helper; see comment for cmpxchg. |
64 template<> |
64 template<> |
65 template<typename I, typename D> |
65 template<typename D, typename I> |
66 inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest, |
66 inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I add_value, |
67 atomic_memory_order order) const { |
67 atomic_memory_order order) const { |
68 STATIC_ASSERT(8 == sizeof(I)); |
68 STATIC_ASSERT(8 == sizeof(I)); |
69 STATIC_ASSERT(8 == sizeof(D)); |
69 STATIC_ASSERT(8 == sizeof(D)); |
70 return PrimitiveConversions::cast<D>( |
70 return PrimitiveConversions::cast<D>( |
71 _Atomic_add_long(PrimitiveConversions::cast<int64_t>(add_value), |
71 _Atomic_add_long(PrimitiveConversions::cast<int64_t>(add_value), |