Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-07 10:16:38

0001 // Copyright (C) 2023 The Qt Company Ltd.
0002 // Copyright (C) 2023 Intel Corporation.
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 // Qt-Security score:significant reason:default
0005 
0006 #ifndef QYIELDCPU_H
0007 #define QYIELDCPU_H
0008 
0009 #include <QtCore/qcompilerdetection.h>
0010 #include <QtCore/qprocessordetection.h>
0011 #include <QtCore/qtconfigmacros.h>
0012 
0013 #ifdef Q_CC_MSVC_ONLY
0014 // MSVC defines _YIELD_PROCESSOR() in <xatomic.h>, but as that is a private
0015 // header, we include the public ones
0016 #  ifdef __cplusplus
0017 #    include <atomic>
0018 extern "C"
0019 #  endif
0020 void _mm_pause(void);       // the compiler recognizes as intrinsic
0021 #endif
0022 
0023 QT_BEGIN_NAMESPACE
0024 
0025 Q_ALWAYS_INLINE
0026 #ifdef Q_CC_GNU
0027 __attribute__((artificial))
0028 #endif
0029 void qYieldCpu(void) Q_DECL_NOEXCEPT;
0030 
0031 void qYieldCpu(void)
0032 #ifdef __cplusplus
0033     noexcept
0034 #endif
0035 {
0036 #if __has_builtin(__yield)
0037     __yield();              // Generic
0038 #elif defined(_YIELD_PROCESSOR) && defined(Q_CC_MSVC)
0039     _YIELD_PROCESSOR();     // Generic; MSVC's <atomic>
0040 
0041 #elif __has_builtin(__builtin_ia32_pause)
0042     __builtin_ia32_pause();
0043 #elif defined(Q_PROCESSOR_X86) && defined(Q_CC_GNU)
0044     // GCC < 10 didn't have __has_builtin()
0045     __builtin_ia32_pause();
0046 #elif defined(Q_PROCESSOR_X86) && defined(Q_CC_MSVC)
0047     _mm_pause();
0048 #elif defined(Q_PROCESSOR_X86)
0049     __asm__("pause");           // hopefully asm() works in this compiler
0050 
0051 #elif __has_builtin(__builtin_arm_yield)
0052     __builtin_arm_yield();
0053 #elif defined(Q_PROCESSOR_ARM) && Q_PROCESSOR_ARM >= 7 && defined(Q_CC_GNU)
0054     __asm__("yield");           // this works everywhere
0055 
0056 #elif defined(Q_PROCESSOR_RISCV)
0057     __asm__(".word 0x0100000f");        // a.k.a. "pause"
0058 
0059 #elif defined(_YIELD_PROCESSOR) && defined(Q_CC_GHS)
0060     _YIELD_PROCESSOR;       // Green Hills (INTEGRITY), but only on ARM
0061 #endif
0062 }
0063 
0064 QT_END_NAMESPACE
0065 
0066 #endif // QYIELDCPU_H