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) 2017 Andrey Semashev
7  */
8 /*!
9  * \file   atomic/detail/extra_ops_msvc_arm.hpp
10  *
11  * This header contains implementation of the extra atomic operations for ARM.
12  */
13 
14 #ifndef BOOST_ATOMIC_DETAIL_EXTRA_OPS_MSVC_ARM_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_EXTRA_OPS_MSVC_ARM_HPP_INCLUDED_
16 
17 #include <cstddef>
18 #include <boost/memory_order.hpp>
19 #include <boost/atomic/detail/config.hpp>
20 #include <boost/atomic/detail/interlocked.hpp>
21 #include <boost/atomic/detail/storage_type.hpp>
22 #include <boost/atomic/detail/extra_operations_fwd.hpp>
23 #include <boost/atomic/detail/extra_ops_generic.hpp>
24 #include <boost/atomic/capabilities.hpp>
25 
26 #ifdef BOOST_HAS_PRAGMA_ONCE
27 #pragma once
28 #endif
29 
30 namespace boost {
31 namespace atomics {
32 namespace detail {
33 
34 #if defined(BOOST_ATOMIC_INTERLOCKED_BTS) && defined(BOOST_ATOMIC_INTERLOCKED_BTR)
35 
36 template< typename Base, std::size_t Size, bool Signed >
37 struct extra_operations< Base, 4u, Signed, true > :
38     public generic_extra_operations< Base, 4u, Signed >
39 {
40     typedef generic_extra_operations< Base, 4u, Signed > base_type;
41     typedef typename base_type::storage_type storage_type;
42 
bit_test_and_setboost::atomics::detail::extra_operations43     static BOOST_FORCEINLINE bool bit_test_and_set(storage_type volatile& storage, unsigned int bit_number, memory_order order) BOOST_NOEXCEPT
44     {
45 #if defined(BOOST_ATOMIC_INTERLOCKED_BTS_RELAXED) && defined(BOOST_ATOMIC_INTERLOCKED_BTS_ACQUIRE) && defined(BOOST_ATOMIC_INTERLOCKED_BTS_RELEASE)
46         bool result;
47         switch (order)
48         {
49         case memory_order_relaxed:
50             result = !!BOOST_ATOMIC_INTERLOCKED_BTS_RELAXED(&storage, bit_number);
51             break;
52         case memory_order_consume:
53         case memory_order_acquire:
54             result = !!BOOST_ATOMIC_INTERLOCKED_BTS_ACQUIRE(&storage, bit_number);
55             break;
56         case memory_order_release:
57             result = !!BOOST_ATOMIC_INTERLOCKED_BTS_RELEASE(&storage, bit_number);
58             break;
59         case memory_order_acq_rel:
60         case memory_order_seq_cst:
61         default:
62             result = !!BOOST_ATOMIC_INTERLOCKED_BTS(&storage, bit_number);
63             break;
64         }
65         return result;
66 #else
67         return !!BOOST_ATOMIC_INTERLOCKED_BTS(&storage, bit_number);
68 #endif
69     }
70 
bit_test_and_resetboost::atomics::detail::extra_operations71     static BOOST_FORCEINLINE bool bit_test_and_reset(storage_type volatile& storage, unsigned int bit_number, memory_order order) BOOST_NOEXCEPT
72     {
73 #if defined(BOOST_ATOMIC_INTERLOCKED_BTR_RELAXED) && defined(BOOST_ATOMIC_INTERLOCKED_BTR_ACQUIRE) && defined(BOOST_ATOMIC_INTERLOCKED_BTR_RELEASE)
74         bool result;
75         switch (order)
76         {
77         case memory_order_relaxed:
78             result = !!BOOST_ATOMIC_INTERLOCKED_BTR_RELAXED(&storage, bit_number);
79             break;
80         case memory_order_consume:
81         case memory_order_acquire:
82             result = !!BOOST_ATOMIC_INTERLOCKED_BTR_ACQUIRE(&storage, bit_number);
83             break;
84         case memory_order_release:
85             result = !!BOOST_ATOMIC_INTERLOCKED_BTR_RELEASE(&storage, bit_number);
86             break;
87         case memory_order_acq_rel:
88         case memory_order_seq_cst:
89         default:
90             result = !!BOOST_ATOMIC_INTERLOCKED_BTR(&storage, bit_number);
91             break;
92         }
93         return result;
94 #else
95         return !!BOOST_ATOMIC_INTERLOCKED_BTR(&storage, bit_number);
96 #endif
97     }
98 };
99 
100 #endif // defined(BOOST_ATOMIC_INTERLOCKED_BTS) && defined(BOOST_ATOMIC_INTERLOCKED_BTR)
101 
102 } // namespace detail
103 } // namespace atomics
104 } // namespace boost
105 
106 #endif // BOOST_ATOMIC_DETAIL_EXTRA_OPS_MSVC_ARM_HPP_INCLUDED_
107