Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qyieldcpu.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// Copyright (C) 2023 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QYIELDCPU_H
6#define QYIELDCPU_H
7
8#include <QtCore/qcompilerdetection.h>
9#include <QtCore/qprocessordetection.h>
10#include <QtCore/qtconfigmacros.h>
11
12#ifdef Q_CC_MSVC_ONLY
13// MSVC defines _YIELD_PROCESSOR() in <xatomic.h>, but as that is a private
14// header, we include the public ones
15# ifdef __cplusplus
16# include <atomic>
17extern "C"
18# endif
19void _mm_pause(void); // the compiler recognizes as intrinsic
20#endif
21
23
24#ifdef Q_CC_GNU
25__attribute__((artificial))
26#endif
28
29void qYieldCpu(void)
30#ifdef __cplusplus
31 noexcept
32#endif
33{
34#if __has_builtin(__yield)
35 __yield(); // Generic
36#elif defined(_YIELD_PROCESSOR) && defined(Q_CC_MSVC)
37 _YIELD_PROCESSOR(); // Generic; MSVC's <atomic>
38
39#elif __has_builtin(__builtin_ia32_pause)
40 __builtin_ia32_pause();
41#elif defined(Q_PROCESSOR_X86) && defined(Q_CC_GNU)
42 // GCC < 10 didn't have __has_builtin()
43 __builtin_ia32_pause();
44#elif defined(Q_PROCESSOR_X86) && defined(Q_CC_MSVC)
45 _mm_pause();
46#elif defined(Q_PROCESSOR_X86)
47 asm("pause"); // hopefully asm() works in this compiler
48
49#elif __has_builtin(__builtin_arm_yield)
50 __builtin_arm_yield();
51#elif defined(Q_PROCESSOR_ARM) && Q_PROCESSOR_ARM >= 7 && defined(Q_CC_GNU)
52 asm("yield"); // this works everywhere
53
54#elif defined(Q_PROCESSOR_RISCV)
55 asm(".word 0x0100000f"); // a.k.a. "pause"
56
57#elif defined(_YIELD_PROCESSOR) && defined(Q_CC_GHS)
58 _YIELD_PROCESSOR; // Green Hills (INTEGRITY), but only on ARM
59#endif
60}
61
63
64#endif // QYIELDCPU_H
struct capHdr __attribute__
Combined button and popup list for selecting options.
#define Q_DECL_NOEXCEPT
#define Q_ALWAYS_INLINE
QT_BEGIN_NAMESPACE Q_ALWAYS_INLINE void qYieldCpu(void) Q_DECL_NOEXCEPT
Definition qyieldcpu.h:29