File indexing completed on 2025-01-30 09:33:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_ATOMIC_DETAIL_FP_OPS_GENERIC_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_FP_OPS_GENERIC_HPP_INCLUDED_
0016
0017 #include <cstddef>
0018 #include <boost/memory_order.hpp>
0019 #include <boost/atomic/detail/config.hpp>
0020 #include <boost/atomic/detail/bitwise_fp_cast.hpp>
0021 #include <boost/atomic/detail/storage_traits.hpp>
0022 #include <boost/atomic/detail/fp_operations_fwd.hpp>
0023 #include <boost/atomic/detail/header.hpp>
0024
0025 #ifdef BOOST_HAS_PRAGMA_ONCE
0026 #pragma once
0027 #endif
0028
0029 namespace boost {
0030 namespace atomics {
0031 namespace detail {
0032
0033
0034 template< typename Base, typename Value, std::size_t Size >
0035 struct fp_operations_generic :
0036 public Base
0037 {
0038 typedef Base base_type;
0039 typedef typename base_type::storage_type storage_type;
0040 typedef Value value_type;
0041
0042 static BOOST_FORCEINLINE value_type fetch_add(storage_type volatile& storage, value_type v, memory_order order) BOOST_NOEXCEPT
0043 {
0044 storage_type old_storage, new_storage;
0045 value_type old_val, new_val;
0046 atomics::detail::non_atomic_load(storage, old_storage);
0047 do
0048 {
0049 old_val = atomics::detail::bitwise_fp_cast< value_type >(old_storage);
0050 new_val = old_val + v;
0051 new_storage = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0052 }
0053 while (!base_type::compare_exchange_weak(storage, old_storage, new_storage, order, memory_order_relaxed));
0054 return old_val;
0055 }
0056
0057 static BOOST_FORCEINLINE value_type fetch_sub(storage_type volatile& storage, value_type v, memory_order order) BOOST_NOEXCEPT
0058 {
0059 storage_type old_storage, new_storage;
0060 value_type old_val, new_val;
0061 atomics::detail::non_atomic_load(storage, old_storage);
0062 do
0063 {
0064 old_val = atomics::detail::bitwise_fp_cast< value_type >(old_storage);
0065 new_val = old_val - v;
0066 new_storage = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0067 }
0068 while (!base_type::compare_exchange_weak(storage, old_storage, new_storage, order, memory_order_relaxed));
0069 return old_val;
0070 }
0071 };
0072
0073
0074 template< typename Base, typename Value, std::size_t Size >
0075 struct fp_operations< Base, Value, Size, true > :
0076 public fp_operations_generic< Base, Value, Size >
0077 {
0078 };
0079
0080 }
0081 }
0082 }
0083
0084 #include <boost/atomic/detail/footer.hpp>
0085
0086 #endif