aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread
diff options
context:
space:
mode:
authorprotty <45520026+kprotty@users.noreply.github.com>2021-05-31 11:11:30 -0500
committerGitHub <noreply@github.com>2021-05-31 11:11:30 -0500
commiteb6975f0889db4c2c29d47bb959bc39bd0a9b167 (patch)
tree688143d7828e2717ed2246c9a2482d8f22433976 /lib/std/Thread
parent57cf9f7ea6d018714cf4afa711799c67ff730f12 (diff)
downloadzig-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')
-rw-r--r--lib/std/Thread/Condition.zig2
-rw-r--r--lib/std/Thread/Mutex.zig4
-rw-r--r--lib/std/Thread/StaticResetEvent.zig4
3 files changed, 5 insertions, 5 deletions
diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig
index a14b57f6b4..d88a6de31e 100644
--- a/lib/std/Thread/Condition.zig
+++ b/lib/std/Thread/Condition.zig
@@ -115,7 +115,7 @@ pub const AtomicCondition = struct {
else => unreachable,
}
},
- else => spinLoopHint(),
+ else => std.atomic.spinLoopHint(),
}
}
}
diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig
index cae4e282de..49f138079d 100644
--- a/lib/std/Thread/Mutex.zig
+++ b/lib/std/Thread/Mutex.zig
@@ -126,7 +126,7 @@ pub const AtomicMutex = struct {
var iter = std.math.min(32, spin + 1);
while (iter > 0) : (iter -= 1)
- std.Thread.spinLoopHint();
+ std.atomic.spinLoopHint();
}
new_state = .waiting;
@@ -149,7 +149,7 @@ pub const AtomicMutex = struct {
else => unreachable,
}
},
- else => std.Thread.spinLoopHint(),
+ else => std.atomic.spinLoopHint(),
}
}
}
diff --git a/lib/std/Thread/StaticResetEvent.zig b/lib/std/Thread/StaticResetEvent.zig
index 75bea463aa..0a6a1d568e 100644
--- a/lib/std/Thread/StaticResetEvent.zig
+++ b/lib/std/Thread/StaticResetEvent.zig
@@ -182,7 +182,7 @@ pub const AtomicEvent = struct {
timer = time.Timer.start() catch return error.TimedOut;
while (@atomicLoad(u32, waiters, .Acquire) != WAKE) {
- std.os.sched_yield() catch std.Thread.spinLoopHint();
+ std.os.sched_yield() catch std.atomic.spinLoopHint();
if (timeout) |timeout_ns| {
if (timer.read() >= timeout_ns)
return error.TimedOut;
@@ -293,7 +293,7 @@ pub const AtomicEvent = struct {
return @intToPtr(?windows.HANDLE, handle);
},
LOADING => {
- std.os.sched_yield() catch std.Thread.spinLoopHint();
+ std.os.sched_yield() catch std.atomic.spinLoopHint();
handle = @atomicLoad(usize, &event_handle, .Monotonic);
},
else => {