]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | |
2 | // Copyright Oliver Kowalke 2016. | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt or copy at | |
5 | // http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_FIBERS_DETAIL_CPU_RELAX_H | |
8 | #define BOOST_FIBERS_DETAIL_CPU_RELAX_H | |
9 | ||
10 | #include <chrono> | |
11 | #include <thread> | |
12 | ||
13 | #include <boost/config.hpp> | |
14 | #include <boost/predef.h> | |
15 | ||
16 | #include <boost/fiber/detail/config.hpp> | |
17 | ||
18 | #if BOOST_COMP_MSVC || BOOST_COMP_MSVC_EMULATED | |
19 | # include <windows.h> | |
20 | #endif | |
21 | ||
22 | #ifdef BOOST_HAS_ABI_HEADERS | |
23 | # include BOOST_ABI_PREFIX | |
24 | #endif | |
25 | ||
26 | namespace boost { | |
27 | namespace fibers { | |
28 | namespace detail { | |
29 | ||
30 | #if BOOST_ARCH_ARM | |
31 | # if BOOST_COMP_MSVC | |
32 | # define cpu_relax() YieldProcessor(); | |
33 | # elif (defined(__ARM_ARCH_6K__) || \ | |
34 | defined(__ARM_ARCH_6Z__) || \ | |
35 | defined(__ARM_ARCH_6ZK__) || \ | |
36 | defined(__ARM_ARCH_6T2__) || \ | |
37 | defined(__ARM_ARCH_7__) || \ | |
38 | defined(__ARM_ARCH_7A__) || \ | |
39 | defined(__ARM_ARCH_7R__) || \ | |
40 | defined(__ARM_ARCH_7M__) || \ | |
41 | defined(__ARM_ARCH_7S__) || \ | |
42 | defined(__ARM_ARCH_8A__) || \ | |
43 | defined(__aarch64__)) | |
44 | // http://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/YGVrZbxYOlU/Vpgy__zeBQAJ | |
45 | // mnemonic 'yield' is supported from ARMv6k onwards | |
46 | # define cpu_relax() asm volatile ("yield" ::: "memory"); | |
47 | # else | |
48 | # define cpu_relax() asm volatile ("nop" ::: "memory"); | |
49 | # endif | |
f67539c2 | 50 | #elif BOOST_ARCH_MIPS && (__mips_isa_rev > 1) |
b32b8144 FG |
51 | # define cpu_relax() asm volatile ("pause" ::: "memory"); |
52 | #elif BOOST_ARCH_PPC | |
53 | // http://code.metager.de/source/xref/gnu/glibc/sysdeps/powerpc/sys/platform/ppc.h | |
54 | // http://stackoverflow.com/questions/5425506/equivalent-of-x86-pause-instruction-for-ppc | |
55 | // mnemonic 'or' shared resource hints | |
56 | // or 27, 27, 27 This form of 'or' provides a hint that performance | |
57 | // will probably be imrpoved if shared resources dedicated | |
58 | // to the executing processor are released for use by other | |
59 | // processors | |
60 | // extended mnemonics (available with POWER7) | |
61 | // yield == or 27, 27, 27 | |
62 | # define cpu_relax() asm volatile ("or 27,27,27" ::: "memory"); | |
63 | #elif BOOST_ARCH_X86 | |
64 | # if BOOST_COMP_MSVC || BOOST_COMP_MSVC_EMULATED | |
65 | # define cpu_relax() YieldProcessor(); | |
66 | # else | |
67 | # define cpu_relax() asm volatile ("pause" ::: "memory"); | |
68 | # endif | |
69 | #else | |
70 | # define cpu_relax() { \ | |
71 | static constexpr std::chrono::microseconds us0{ 0 }; \ | |
72 | std::this_thread::sleep_for( us0); \ | |
73 | } | |
74 | #endif | |
75 | ||
76 | }}} | |
77 | ||
78 | #ifdef BOOST_HAS_ABI_HEADERS | |
79 | # include BOOST_ABI_SUFFIX | |
80 | #endif | |
81 | ||
82 | #endif // BOOST_FIBERS_DETAIL_CPU_RELAX_H |