pause.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. * (C) Copyright 2013 Tim Blechmann
  7. * (C) Copyright 2013, 2020 Andrey Semashev
  8. */
  9. #ifndef BOOST_ATOMIC_DETAIL_PAUSE_HPP_INCLUDED_
  10. #define BOOST_ATOMIC_DETAIL_PAUSE_HPP_INCLUDED_
  11. #include <boost/atomic/detail/config.hpp>
  12. #include <boost/atomic/detail/header.hpp>
  13. #ifdef BOOST_HAS_PRAGMA_ONCE
  14. #pragma once
  15. #endif
  16. #if defined(_MSC_VER)
  17. #if defined(_M_AMD64) || defined(_M_IX86)
  18. extern "C" void _mm_pause(void);
  19. #if defined(BOOST_MSVC)
  20. #pragma intrinsic(_mm_pause)
  21. #endif
  22. #elif defined(_M_ARM64) || defined(_M_ARM)
  23. extern "C" void __yield(void);
  24. #if defined(BOOST_MSVC)
  25. #pragma intrinsic(__yield)
  26. #endif
  27. #endif
  28. #endif
  29. namespace boost {
  30. namespace atomics {
  31. namespace detail {
  32. BOOST_FORCEINLINE void pause() BOOST_NOEXCEPT
  33. {
  34. #if defined(_MSC_VER)
  35. #if defined(_M_AMD64) || defined(_M_IX86)
  36. _mm_pause();
  37. #elif defined(_M_ARM64) || defined(_M_ARM)
  38. __yield();
  39. #endif
  40. #elif defined(__GNUC__)
  41. #if defined(__i386__) || defined(__x86_64__)
  42. __asm__ __volatile__("pause;" : : : "memory");
  43. #elif (defined(__ARM_ARCH) && __ARM_ARCH >= 8) || defined(__ARM_ARCH_8A__) || defined(__aarch64__)
  44. __asm__ __volatile__("yield;" : : : "memory");
  45. #endif
  46. #endif
  47. }
  48. } // namespace detail
  49. } // namespace atomics
  50. } // namespace boost
  51. #include <boost/atomic/detail/footer.hpp>
  52. #endif // BOOST_ATOMIC_DETAIL_PAUSE_HPP_INCLUDED_