diff options
| author | protty <45520026+kprotty@users.noreply.github.com> | 2021-05-31 11:11:30 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-31 11:11:30 -0500 |
| commit | eb6975f0889db4c2c29d47bb959bc39bd0a9b167 (patch) | |
| tree | 688143d7828e2717ed2246c9a2482d8f22433976 /lib/std/Thread.zig | |
| parent | 57cf9f7ea6d018714cf4afa711799c67ff730f12 (diff) | |
| download | zig-eb6975f0889db4c2c29d47bb959bc39bd0a9b167.tar.gz zig-eb6975f0889db4c2c29d47bb959bc39bd0a9b167.zip | |
std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index fbb3d927e2..fb74f09677 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -67,33 +67,7 @@ else switch (std.Target.current.os.tag) { else => struct {}, }; -/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock"). -pub inline fn spinLoopHint() void { - switch (std.Target.current.cpu.arch) { - .i386, .x86_64 => { - asm volatile ("pause" ::: "memory"); - }, - .arm, .armeb, .thumb, .thumbeb => { - // `yield` was introduced in v6k but are also available on v6m. - const can_yield = comptime std.Target.arm.featureSetHasAny(std.Target.current.cpu.features, .{ .has_v6k, .has_v6m }); - if (can_yield) asm volatile ("yield" ::: "memory") - // Fallback. - else asm volatile ("" ::: "memory"); - }, - .aarch64, .aarch64_be, .aarch64_32 => { - asm volatile ("isb" ::: "memory"); - }, - .powerpc64, .powerpc64le => { - // No-op that serves as `yield` hint. - asm volatile ("or 27, 27, 27" ::: "memory"); - }, - else => { - // Do nothing but prevent the compiler from optimizing away the - // spinning loop. - asm volatile ("" ::: "memory"); - }, - } -} +pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint"); /// Returns the ID of the calling thread. /// Makes a syscall every time the function is called. @@ -597,8 +571,13 @@ pub fn getCurrentThreadId() u64 { } } -test { +test "std.Thread" { if (!builtin.single_threaded) { - std.testing.refAllDecls(@This()); + _ = AutoResetEvent; + _ = ResetEvent; + _ = StaticResetEvent; + _ = Mutex; + _ = Semaphore; + _ = Condition; } } |
