| ... | ... | @@ -68,11 +68,28 @@ else switch (std.Target.current.os.tag) { |
| 68 | 68 | }; |
| 69 | 69 | |
| 70 | 70 | /// Signals the processor that it is inside a busy-wait spin-loop ("spin lock"). |
| 71 | | pub fn spinLoopHint() void { |
| 71 | pub fn spinLoopHint() callconv(.Inline) void { |
| 72 | 72 | switch (std.Target.current.cpu.arch) { |
| 73 | | .i386, .x86_64 => asm volatile ("pause" ::: "memory"), |
| 74 | | .arm, .aarch64 => asm volatile ("yield" ::: "memory"), |
| 75 | | else => {}, |
| 73 | .i386, .x86_64 => { |
| 74 | asm volatile ("pause" ::: "memory"); |
| 75 | }, |
| 76 | .arm, .armeb, .thumb, .thumbeb => { |
| 77 | // `yield` was introduced in v6k but are also available on v6m. |
| 78 | const can_yield = comptime std.Target.arm.featureSetHas(std.Target.current.cpu.features, .has_v6m); |
| 79 | if (can_yield) asm volatile ("yield" ::: "memory"); |
| 80 | }, |
| 81 | .aarch64, .aarch64_be, .aarch64_32 => { |
| 82 | asm volatile ("isb" ::: "memory"); |
| 83 | }, |
| 84 | .powerpc64, .powerpc64le => { |
| 85 | // No-op that serves as `yield` hint. |
| 86 | asm volatile ("or 27, 27, 27" ::: "memory"); |
| 87 | }, |
| 88 | else => { |
| 89 | // Do nothing but prevent the compiler from optimizing away the |
| 90 | // spinning loop. |
| 91 | asm volatile ("" ::: "memory"); |
| 92 | }, |
| 76 | 93 | } |
| 77 | 94 | } |
| 78 | 95 | |