Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
cpu_instructions.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/target_posix/roc_core/cpu_instructions.h
10//! @brief CPU-specific instructions.
11
12#ifndef ROC_CORE_CPU_INSTRUCTIONS_H_
13#define ROC_CORE_CPU_INSTRUCTIONS_H_
14
15namespace roc {
16namespace core {
17
18#ifdef __GNUC__
19
20#if defined(__i386__) || defined(__x86_64__)
21
22inline void cpu_relax() {
23 __asm__ __volatile__("pause" ::: "memory");
24}
25
26#elif defined(__aarch64__)
27
28inline void cpu_relax() {
29 __asm__ __volatile__("yield" ::: "memory");
30}
31
32#else // unknown arch
33
34inline void cpu_relax() {
35 __asm__ __volatile__("" ::: "memory");
36}
37
38#endif
39
40#else // !__GNUC__
41
42//! CPU pause instruction.
43//! @remarks
44//! Doesn't include any memory barriers, so the caller is responsible to
45//! insert them into the loop. Allowed to expand to nothing.
46inline void cpu_relax() {
47}
48
49#endif // __GNUC__
50
51} // namespace core
52} // namespace roc
53
54#endif // ROC_CORE_CPU_INSTRUCTIONS_H_
void cpu_relax()
CPU pause instruction.
Root namespace.