extra_ops_msvc_arm.hpp 3.6 KB

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