Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:54

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * Copyright (c) 2018 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/extra_fp_ops_emulated.hpp
0010  *
0011  * This header contains emulated (lock-based) implementation of the extra floating point atomic operations.
0012  */
0013 
0014 #ifndef BOOST_ATOMIC_DETAIL_EXTRA_FP_OPS_EMULATED_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_EXTRA_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/extra_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 //! Emulated implementation of extra floating point operations
0033 template< typename Base, typename Value, std::size_t Size >
0034 struct extra_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_negate(storage_type volatile& storage, 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;
0049         s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0050         return old_val;
0051     }
0052 
0053     static value_type negate(storage_type volatile& storage, 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;
0060         s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0061         return new_val;
0062     }
0063 
0064     static value_type add(storage_type volatile& storage, value_type v, memory_order) BOOST_NOEXCEPT
0065     {
0066         static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0067         storage_type& s = const_cast< storage_type& >(storage);
0068         scoped_lock lock(&storage);
0069         value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
0070         value_type new_val = old_val + v;
0071         s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0072         return new_val;
0073     }
0074 
0075     static value_type sub(storage_type volatile& storage, value_type v, memory_order) BOOST_NOEXCEPT
0076     {
0077         static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0078         storage_type& s = const_cast< storage_type& >(storage);
0079         scoped_lock lock(&storage);
0080         value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
0081         value_type new_val = old_val - v;
0082         s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
0083         return new_val;
0084     }
0085 
0086     static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
0087     {
0088         static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0089         fetch_negate(storage, order);
0090     }
0091 
0092     static BOOST_FORCEINLINE void opaque_add(storage_type volatile& storage, value_type v, memory_order order) BOOST_NOEXCEPT
0093     {
0094         static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0095         base_type::fetch_add(storage, v, order);
0096     }
0097 
0098     static BOOST_FORCEINLINE void opaque_sub(storage_type volatile& storage, value_type v, memory_order order) BOOST_NOEXCEPT
0099     {
0100         static_assert(!base_type::is_interprocess, "Boost.Atomic: operation invoked on a non-lock-free inter-process atomic object");
0101         base_type::fetch_sub(storage, v, order);
0102     }
0103 };
0104 
0105 template< typename Base, typename Value, std::size_t Size >
0106 struct extra_fp_operations< Base, Value, Size, false > :
0107     public extra_fp_operations_emulated< Base, Value, Size >
0108 {
0109 };
0110 
0111 } // namespace detail
0112 } // namespace atomics
0113 } // namespace boost
0114 
0115 #include <boost/atomic/detail/footer.hpp>
0116 
0117 #endif // BOOST_ATOMIC_DETAIL_EXTRA_FP_OPS_EMULATED_HPP_INCLUDED_