]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/atomic/detail/extra_fp_ops_emulated.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / atomic / detail / extra_fp_ops_emulated.hpp
1 /*
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * Copyright (c) 2018 Andrey Semashev
7 */
8 /*!
9 * \file atomic/detail/extra_fp_ops_emulated.hpp
10 *
11 * This header contains emulated (lock-based) implementation of the extra floating point atomic operations.
12 */
13
14 #ifndef BOOST_ATOMIC_DETAIL_EXTRA_FP_OPS_EMULATED_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_EXTRA_FP_OPS_EMULATED_HPP_INCLUDED_
16
17 #include <cstddef>
18 #include <boost/memory_order.hpp>
19 #include <boost/atomic/detail/config.hpp>
20 #include <boost/atomic/detail/bitwise_fp_cast.hpp>
21 #include <boost/atomic/detail/extra_fp_operations_fwd.hpp>
22 #include <boost/atomic/detail/lockpool.hpp>
23
24 #ifdef BOOST_HAS_PRAGMA_ONCE
25 #pragma once
26 #endif
27
28 namespace boost {
29 namespace atomics {
30 namespace detail {
31
32 //! Generic implementation of extra floating point operations
33 template< typename Base, typename Value, std::size_t Size >
34 struct emulated_extra_fp_operations :
35 public Base
36 {
37 typedef Base base_type;
38 typedef typename base_type::storage_type storage_type;
39 typedef Value value_type;
40
41 static BOOST_FORCEINLINE value_type fetch_negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
42 {
43 storage_type& s = const_cast< storage_type& >(storage);
44 lockpool::scoped_lock lock(&storage);
45 value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
46 value_type new_val = -old_val;
47 s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
48 return old_val;
49 }
50
51 static BOOST_FORCEINLINE value_type negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
52 {
53 storage_type& s = const_cast< storage_type& >(storage);
54 lockpool::scoped_lock lock(&storage);
55 value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
56 value_type new_val = -old_val;
57 s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
58 return new_val;
59 }
60
61 static BOOST_FORCEINLINE value_type add(storage_type volatile& storage, value_type v, memory_order) BOOST_NOEXCEPT
62 {
63 storage_type& s = const_cast< storage_type& >(storage);
64 lockpool::scoped_lock lock(&storage);
65 value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
66 value_type new_val = old_val + v;
67 s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
68 return new_val;
69 }
70
71 static BOOST_FORCEINLINE value_type sub(storage_type volatile& storage, value_type v, memory_order) BOOST_NOEXCEPT
72 {
73 storage_type& s = const_cast< storage_type& >(storage);
74 lockpool::scoped_lock lock(&storage);
75 value_type old_val = atomics::detail::bitwise_fp_cast< value_type >(s);
76 value_type new_val = old_val - v;
77 s = atomics::detail::bitwise_fp_cast< storage_type >(new_val);
78 return new_val;
79 }
80
81 static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
82 {
83 fetch_negate(storage, order);
84 }
85
86 static BOOST_FORCEINLINE void opaque_add(storage_type volatile& storage, value_type v, memory_order order) BOOST_NOEXCEPT
87 {
88 base_type::fetch_add(storage, v, order);
89 }
90
91 static BOOST_FORCEINLINE void opaque_sub(storage_type volatile& storage, value_type v, memory_order order) BOOST_NOEXCEPT
92 {
93 base_type::fetch_sub(storage, v, order);
94 }
95 };
96
97 template< typename Base, typename Value, std::size_t Size >
98 struct extra_fp_operations< Base, Value, Size, false > :
99 public emulated_extra_fp_operations< Base, Value, Size >
100 {
101 };
102
103 } // namespace detail
104 } // namespace atomics
105 } // namespace boost
106
107 #endif // BOOST_ATOMIC_DETAIL_EXTRA_FP_OPS_EMULATED_HPP_INCLUDED_