sp_thread_pause.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED
  2. #define BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // boost/core/detail/sp_thread_pause.hpp
  8. //
  9. // inline void bost::core::sp_thread_pause();
  10. //
  11. // Emits a "pause" instruction.
  12. //
  13. // Copyright 2008, 2020, 2023 Peter Dimov
  14. // Distributed under the Boost Software License, Version 1.0
  15. // https://www.boost.org/LICENSE_1_0.txt
  16. #include <boost/config.hpp>
  17. #if defined(__has_builtin)
  18. # if __has_builtin(__builtin_ia32_pause) && !defined(__INTEL_COMPILER)
  19. # define BOOST_CORE_HAS_BUILTIN_IA32_PAUSE
  20. # endif
  21. #endif
  22. #if defined(BOOST_CORE_HAS_BUILTIN_IA32_PAUSE)
  23. # define BOOST_CORE_SP_PAUSE() __builtin_ia32_pause()
  24. #elif defined(_MSC_VER) && ( defined(_M_IX86) || defined(_M_X64) )
  25. # include <intrin.h>
  26. # define BOOST_CORE_SP_PAUSE() _mm_pause()
  27. #elif defined(_MSC_VER) && ( defined(_M_ARM) || defined(_M_ARM64) )
  28. # include <intrin.h>
  29. # define BOOST_CORE_SP_PAUSE() __yield()
  30. #elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
  31. # define BOOST_CORE_SP_PAUSE() __asm__ __volatile__( "rep; nop" : : : "memory" )
  32. #elif defined(__GNUC__) && ( (defined(__ARM_ARCH) && __ARM_ARCH >= 8) || defined(__ARM_ARCH_8A__) || defined(__aarch64__) )
  33. # define BOOST_CORE_SP_PAUSE() __asm__ __volatile__( "yield" : : : "memory" )
  34. #else
  35. # define BOOST_CORE_SP_PAUSE() ((void)0)
  36. #endif
  37. namespace boost
  38. {
  39. namespace core
  40. {
  41. BOOST_FORCEINLINE void sp_thread_pause() BOOST_NOEXCEPT
  42. {
  43. BOOST_CORE_SP_PAUSE();
  44. }
  45. } // namespace core
  46. } // namespace boost
  47. #undef BOOST_CORE_SP_PAUSE
  48. #endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED