Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:38:47

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.
0003  *    (See accompanying file LICENSE_1_0.txt or copy at
0004  *          http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * (C) Copyright 2013 Tim Blechmann
0007  * (C) Copyright 2013, 2020-2025 Andrey Semashev
0008  */
0009 
0010 #ifndef BOOST_ATOMIC_THREAD_PAUSE_HPP_INCLUDED_
0011 #define BOOST_ATOMIC_THREAD_PAUSE_HPP_INCLUDED_
0012 
0013 #include <boost/atomic/detail/config.hpp>
0014 #if defined(_MSC_VER)
0015 #include <boost/atomic/detail/ops_msvc_common.hpp>
0016 #endif
0017 #include <boost/atomic/detail/header.hpp>
0018 
0019 #ifdef BOOST_HAS_PRAGMA_ONCE
0020 #pragma once
0021 #endif
0022 
0023 #if defined(_MSC_VER)
0024 // (sigh, shake head) _M_ARM64EC and _M_AMD64 may be defined both
0025 // https://learn.microsoft.com/en-us/windows/arm/arm64ec-abi
0026 #if defined(_M_ARM64) || defined(_M_ARM64EC)
0027 extern "C" void __isb(unsigned int);
0028 #if defined(BOOST_MSVC)
0029 #pragma intrinsic(__isb)
0030 #endif
0031 #elif defined(_M_ARM)
0032 extern "C" void __yield(void);
0033 #if defined(BOOST_MSVC)
0034 #pragma intrinsic(__yield)
0035 #endif
0036 #elif defined(_M_AMD64) || defined(_M_IX86)
0037 extern "C" void _mm_pause(void);
0038 #if defined(BOOST_MSVC)
0039 #pragma intrinsic(_mm_pause)
0040 #endif
0041 #endif
0042 #endif
0043 
0044 #if defined(sun) || defined(__sun)
0045 // Avoid including synch.h
0046 extern "C" void smt_pause(void);
0047 #endif
0048 
0049 namespace boost {
0050 namespace atomics {
0051 
0052 //! The function pauses for a number of CPU cycles, potentially freeing CPU resources, allowing sibling threads to progress. May be a no-op.
0053 BOOST_FORCEINLINE void thread_pause() noexcept
0054 {
0055 #if defined(_MSC_VER)
0056 
0057     BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
0058 #if defined(_M_ARM64) || defined(_M_ARM64EC)
0059     __isb(0xF); // ISB SY
0060 #elif defined(_M_ARM)
0061     __yield();
0062 #elif defined(_M_AMD64) || defined(_M_IX86)
0063     _mm_pause();
0064 #endif
0065     BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
0066 
0067 #elif defined(__GNUC__)
0068 
0069 #if defined(__i386__) || defined(__x86_64__)
0070     __asm__ __volatile__("pause" : : : "memory");
0071 #elif defined(__aarch64__)
0072     // https://github.com/rust-lang/rust/commit/c064b6560b7ce0adeb9bbf5d7dcf12b1acb0c807
0073     // https://web.archive.org/web/20231004132033/https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8258604
0074     __asm__ __volatile__("isb" : : : "memory");
0075 #elif (defined(__ARM_ARCH) && __ARM_ARCH >= 8) || defined(__ARM_ARCH_8A__)
0076     __asm__ __volatile__("yield" : : : "memory");
0077 #elif (defined(__POWERPC__) || defined(__PPC__))
0078     __asm__ __volatile__("or 27,27,27" : : : "memory"); // yield pseudo-instruction
0079 #elif defined(__riscv) && (__riscv_xlen == 64)
0080 #if defined(__riscv_zihintpause)
0081     __asm__ __volatile__("pause" : : : "memory");
0082 #else
0083     // Encoding of the pause instruction
0084     __asm__ __volatile__ (".4byte 0x100000F" : : : "memory");
0085 #endif
0086 #elif defined(sun) || defined(__sun)
0087     smt_pause();
0088 #endif
0089 
0090 #elif defined(sun) || defined(__sun)
0091 
0092     smt_pause();
0093 
0094 #endif
0095 }
0096 
0097 } // namespace atomics
0098 } // namespace boost
0099 
0100 #include <boost/atomic/detail/footer.hpp>
0101 
0102 #endif // BOOST_ATOMIC_THREAD_PAUSE_HPP_INCLUDED_