File indexing completed on 2024-11-15 09:03:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_ATOMIC_DETAIL_FP_OPS_EMULATED_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_FP_OPS_EMULATED_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/fp_operations_fwd.hpp>
0022 #include <boost/atomic/detail/header.hpp>
0023
0024 #ifdef BOOST_HAS_PRAGMA_ONCE
0025 #pragma once
0026 #endif
0027
0028 namespace boost {
0029 namespace atomics {
0030 namespace detail {
0031
0032
0033 template< typename Base, typename Value, std::size_t Size >
0034 struct fp_operations_emulated :
0035 public Base
0036 {
0037 typedef Base base_type;
0038 typedef typename base_type::storage_type storage_type;
0039 typedef Value value_type;
0040 typedef typename base_type::scoped_lock scoped_lock;
0041
0042 static value_type fetch_add(storage_type volatile& storage, value_type v, memory_order) BOOST_NOEXCEPT
0043 {
0044 static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0045 storage_type& s = const_cast< storage_type& >(storage);
0046 scoped_lock lock(&storage);
0047 value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
0048 value_type new_val = old_val + v;
0049 s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0050 return old_val;
0051 }
0052
0053 static value_type fetch_sub(storage_type volatile& storage, value_type v, memory_order) BOOST_NOEXCEPT
0054 {
0055 static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0056 storage_type& s = const_cast< storage_type& >(storage);
0057 scoped_lock lock(&storage);
0058 value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
0059 value_type new_val = old_val - v;
0060 s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0061 return old_val;
0062 }
0063 };
0064
0065 template< typename Base, typename Value, std::size_t Size >
0066 struct fp_operations< Base, Value, Size, false > :
0067 public fp_operations_emulated< Base, Value, Size >
0068 {
0069 };
0070
0071 }
0072 }
0073 }
0074
0075 #include <boost/atomic/detail/footer.hpp>
0076
0077 #endif