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