Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- Utilities for suspending threads ----------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_SLEEP_H |
10 | #define LLVM_LIBC_SRC___SUPPORT_THREADS_SLEEP_H |
11 | |
12 | #include "src/__support/macros/attributes.h" |
13 | #include "src/__support/macros/config.h" |
14 | |
15 | namespace LIBC_NAMESPACE_DECL { |
16 | |
17 | /// Suspend the thread briefly to assist the thread scheduler during busy loops. |
18 | LIBC_INLINE void sleep_briefly() { |
19 | #if defined(LIBC_TARGET_ARCH_IS_NVPTX) |
20 | if (__nvvm_reflect("__CUDA_ARCH") >= 700) |
21 | LIBC_INLINE_ASM("nanosleep.u32 64;" ::: "memory"); |
22 | #elif defined(LIBC_TARGET_ARCH_IS_AMDGPU) |
23 | __builtin_amdgcn_s_sleep(2); |
24 | #elif defined(LIBC_TARGET_ARCH_IS_X86) |
25 | __builtin_ia32_pause(); |
26 | #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) && __has_builtin(__builtin_arm_isb) |
27 | __builtin_arm_isb(0xf); |
28 | #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) |
29 | asm volatile("isb\n" ::: "memory"); |
30 | #else |
31 | // Simply do nothing if sleeping isn't supported on this platform. |
32 | #endif |
33 | } |
34 | |
35 | } // namespace LIBC_NAMESPACE_DECL |
36 | |
37 | #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_SLEEP_H |
38 |
Warning: This file is not a C or C++ file. It does not have highlighting.