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
This commit is contained in:
@@ -115,7 +115,7 @@ pub const AtomicCondition = struct {
|
||||
else => unreachable,
|
||||
}
|
||||
},
|
||||
else => spinLoopHint(),
|
||||
else => std.atomic.spinLoopHint(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user