File indexing completed on 2025-01-30 09:33:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_ATOMIC_DETAIL_CORE_OPS_GCC_ATOMIC_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_CORE_OPS_GCC_ATOMIC_HPP_INCLUDED_
0016
0017 #include <cstddef>
0018 #include <boost/memory_order.hpp>
0019 #include <boost/atomic/detail/config.hpp>
0020 #include <boost/atomic/detail/storage_traits.hpp>
0021 #include <boost/atomic/detail/core_operations_fwd.hpp>
0022 #include <boost/atomic/detail/core_arch_operations.hpp>
0023 #include <boost/atomic/detail/capabilities.hpp>
0024 #include <boost/atomic/detail/gcc_atomic_memory_order_utils.hpp>
0025
0026 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT8_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE || BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE ||\
0027 BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE || BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE
0028
0029 #include <boost/atomic/detail/int_sizes.hpp>
0030 #include <boost/atomic/detail/extending_cas_based_arithmetic.hpp>
0031 #endif
0032 #include <boost/atomic/detail/header.hpp>
0033
0034 #ifdef BOOST_HAS_PRAGMA_ONCE
0035 #pragma once
0036 #endif
0037
0038 #if defined(__INTEL_COMPILER)
0039
0040
0041
0042
0043
0044 #pragma system_header
0045 #endif
0046
0047 namespace boost {
0048 namespace atomics {
0049 namespace detail {
0050
0051 template< std::size_t Size, bool Signed, bool Interprocess >
0052 struct core_operations_gcc_atomic
0053 {
0054 typedef typename storage_traits< Size >::type storage_type;
0055
0056 static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = Size;
0057 static BOOST_CONSTEXPR_OR_CONST std::size_t storage_alignment = storage_traits< Size >::alignment;
0058 static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
0059 static BOOST_CONSTEXPR_OR_CONST bool is_interprocess = Interprocess;
0060 static BOOST_CONSTEXPR_OR_CONST bool full_cas_based = false;
0061
0062
0063
0064
0065 static BOOST_CONSTEXPR_OR_CONST bool is_always_lock_free = true;
0066
0067 static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0068 {
0069 #if defined(BOOST_GCC) && BOOST_GCC < 100100 && (defined(__x86_64__) || defined(__i386__))
0070
0071 if (order != memory_order_seq_cst)
0072 __atomic_store_n(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0073 else
0074 __atomic_exchange_n(&storage, v, __ATOMIC_SEQ_CST);
0075 #else
0076 __atomic_store_n(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0077 #endif
0078 }
0079
0080 static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT
0081 {
0082 #if defined(BOOST_ATOMIC_DETAIL_AARCH64_HAS_RCPC)
0083
0084
0085 typedef atomics::detail::core_arch_operations< storage_size, is_signed, is_interprocess > core_arch_operations;
0086 return core_arch_operations::load(storage, order);
0087 #else
0088 return __atomic_load_n(&storage, atomics::detail::convert_memory_order_to_gcc(order));
0089 #endif
0090 }
0091
0092 static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0093 {
0094 return __atomic_fetch_add(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0095 }
0096
0097 static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0098 {
0099 return __atomic_fetch_sub(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0100 }
0101
0102 static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0103 {
0104 return __atomic_exchange_n(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0105 }
0106
0107 static BOOST_FORCEINLINE bool compare_exchange_strong(
0108 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
0109 {
0110 return __atomic_compare_exchange_n
0111 (
0112 &storage, &expected, desired, false,
0113 atomics::detail::convert_memory_order_to_gcc(success_order),
0114 atomics::detail::convert_memory_order_to_gcc(failure_order)
0115 );
0116 }
0117
0118 static BOOST_FORCEINLINE bool compare_exchange_weak(
0119 storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
0120 {
0121 return __atomic_compare_exchange_n
0122 (
0123 &storage, &expected, desired, true,
0124 atomics::detail::convert_memory_order_to_gcc(success_order),
0125 atomics::detail::convert_memory_order_to_gcc(failure_order)
0126 );
0127 }
0128
0129 static BOOST_FORCEINLINE storage_type fetch_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0130 {
0131 return __atomic_fetch_and(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0132 }
0133
0134 static BOOST_FORCEINLINE storage_type fetch_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0135 {
0136 return __atomic_fetch_or(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0137 }
0138
0139 static BOOST_FORCEINLINE storage_type fetch_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0140 {
0141 return __atomic_fetch_xor(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));
0142 }
0143
0144 static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
0145 {
0146 return __atomic_test_and_set(&storage, atomics::detail::convert_memory_order_to_gcc(order));
0147 }
0148
0149 static BOOST_FORCEINLINE void clear(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
0150 {
0151 __atomic_clear(const_cast< storage_type* >(&storage), atomics::detail::convert_memory_order_to_gcc(order));
0152 }
0153 };
0154
0155
0156
0157
0158
0159 #if BOOST_ATOMIC_INT128_LOCK_FREE > 0 && BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE >= BOOST_ATOMIC_INT128_LOCK_FREE
0160
0161 template< bool Signed, bool Interprocess >
0162 struct core_operations< 16u, Signed, Interprocess > :
0163 public core_operations_gcc_atomic< 16u, Signed, Interprocess >
0164 {
0165 };
0166
0167 #endif
0168
0169 #if BOOST_ATOMIC_INT64_LOCK_FREE > 0
0170 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE >= BOOST_ATOMIC_INT64_LOCK_FREE
0171
0172 template< bool Signed, bool Interprocess >
0173 struct core_operations< 8u, Signed, Interprocess > :
0174 public core_operations_gcc_atomic< 8u, Signed, Interprocess >
0175 {
0176 };
0177
0178 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE >= BOOST_ATOMIC_INT64_LOCK_FREE
0179
0180 template< bool Signed, bool Interprocess >
0181 struct core_operations< 8u, Signed, Interprocess > :
0182 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 16u, Signed, Interprocess >, 8u, Signed >
0183 {
0184 };
0185
0186 #endif
0187 #endif
0188
0189
0190 #if BOOST_ATOMIC_INT32_LOCK_FREE > 0
0191 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE >= BOOST_ATOMIC_INT32_LOCK_FREE
0192
0193 template< bool Signed, bool Interprocess >
0194 struct core_operations< 4u, Signed, Interprocess > :
0195 public core_operations_gcc_atomic< 4u, Signed, Interprocess >
0196 {
0197 };
0198
0199 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE >= BOOST_ATOMIC_INT32_LOCK_FREE
0200
0201 template< bool Signed, bool Interprocess >
0202 struct core_operations< 4u, Signed, Interprocess > :
0203 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 8u, Signed, Interprocess >, 4u, Signed >
0204 {
0205 };
0206
0207 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE >= BOOST_ATOMIC_INT32_LOCK_FREE
0208
0209 template< bool Signed, bool Interprocess >
0210 struct core_operations< 8u, Signed, Interprocess > :
0211 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 16u, Signed, Interprocess >, 4u, Signed >
0212 {
0213 };
0214
0215 #endif
0216 #endif
0217
0218
0219 #if BOOST_ATOMIC_INT16_LOCK_FREE > 0
0220 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE >= BOOST_ATOMIC_INT16_LOCK_FREE
0221
0222 template< bool Signed, bool Interprocess >
0223 struct core_operations< 2u, Signed, Interprocess > :
0224 public core_operations_gcc_atomic< 2u, Signed, Interprocess >
0225 {
0226 };
0227
0228 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE >= BOOST_ATOMIC_INT16_LOCK_FREE
0229
0230 template< bool Signed, bool Interprocess >
0231 struct core_operations< 2u, Signed, Interprocess > :
0232 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 4u, Signed, Interprocess >, 2u, Signed >
0233 {
0234 };
0235
0236 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE >= BOOST_ATOMIC_INT16_LOCK_FREE
0237
0238 template< bool Signed, bool Interprocess >
0239 struct core_operations< 2u, Signed, Interprocess > :
0240 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 8u, Signed, Interprocess >, 2u, Signed >
0241 {
0242 };
0243
0244 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE >= BOOST_ATOMIC_INT16_LOCK_FREE
0245
0246 template< bool Signed, bool Interprocess >
0247 struct core_operations< 2u, Signed, Interprocess > :
0248 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 16u, Signed, Interprocess >, 2u, Signed >
0249 {
0250 };
0251
0252 #endif
0253 #endif
0254
0255
0256 #if BOOST_ATOMIC_INT8_LOCK_FREE > 0
0257 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT8_LOCK_FREE >= BOOST_ATOMIC_INT8_LOCK_FREE
0258
0259 template< bool Signed, bool Interprocess >
0260 struct core_operations< 1u, Signed, Interprocess > :
0261 public core_operations_gcc_atomic< 1u, Signed, Interprocess >
0262 {
0263 };
0264
0265 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE >= BOOST_ATOMIC_INT8_LOCK_FREE
0266
0267 template< bool Signed, bool Interprocess >
0268 struct core_operations< 1u, Signed, Interprocess > :
0269 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 2u, Signed, Interprocess >, 1u, Signed >
0270 {
0271 };
0272
0273 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE >= BOOST_ATOMIC_INT8_LOCK_FREE
0274
0275 template< bool Signed, bool Interprocess >
0276 struct core_operations< 1u, Signed, Interprocess > :
0277 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 4u, Signed, Interprocess >, 1u, Signed >
0278 {
0279 };
0280
0281 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE >= BOOST_ATOMIC_INT8_LOCK_FREE
0282
0283 template< bool Signed, bool Interprocess >
0284 struct core_operations< 1u, Signed, Interprocess > :
0285 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 8u, Signed, Interprocess >, 1u, Signed >
0286 {
0287 };
0288
0289 #elif BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE >= BOOST_ATOMIC_INT8_LOCK_FREE
0290
0291 template< bool Signed, bool Interprocess >
0292 struct core_operations< 1u, Signed, Interprocess > :
0293 public extending_cas_based_arithmetic< core_operations_gcc_atomic< 16u, Signed, Interprocess >, 1u, Signed >
0294 {
0295 };
0296
0297 #endif
0298 #endif
0299
0300 }
0301 }
0302 }
0303
0304 #include <boost/atomic/detail/footer.hpp>
0305
0306 #endif