Skip to content

Commit

Permalink
std.Progress: relax some of the atomic orderings
Browse files Browse the repository at this point in the history
Generates better machine code, particularly on ARM
  • Loading branch information
andrewrk committed May 28, 2024
1 parent 5bdfe22 commit 65a0e14
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/std/Progress.zig
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ pub const Node = struct {
// `estimated_total_count` max int indicates the special state that
// causes `completed_count` to be treated as a file descriptor, so
// the order here matters.
@atomicStore(u32, &s.completed_count, integer, .seq_cst);
@atomicStore(u32, &s.estimated_total_count, std.math.maxInt(u32), .seq_cst);
@atomicStore(u32, &s.completed_count, integer, .monotonic);
@atomicStore(u32, &s.estimated_total_count, std.math.maxInt(u32), .release);
}

/// Not thread-safe.
Expand Down Expand Up @@ -590,13 +590,13 @@ fn serialize(serialized_buffer: *Serialized.Buffer) Serialized {
const node_parents = global_progress.node_parents[0..end_index];
const node_storage = global_progress.node_storage[0..end_index];
for (node_parents, node_storage, 0..) |*parent_ptr, *storage_ptr, i| {
var begin_parent = @atomicLoad(Node.Parent, parent_ptr, .seq_cst);
var begin_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire);
while (begin_parent != .unused) {
const dest_storage = &serialized_buffer.storage[serialized_len];
@memcpy(&dest_storage.name, &storage_ptr.name);
dest_storage.completed_count = @atomicLoad(u32, &storage_ptr.completed_count, .seq_cst);
dest_storage.estimated_total_count = @atomicLoad(u32, &storage_ptr.estimated_total_count, .seq_cst);
const end_parent = @atomicLoad(Node.Parent, parent_ptr, .seq_cst);
dest_storage.estimated_total_count = @atomicLoad(u32, &storage_ptr.estimated_total_count, .acquire);
dest_storage.completed_count = @atomicLoad(u32, &storage_ptr.completed_count, .monotonic);
const end_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire);
if (begin_parent == end_parent) {
any_ipc = any_ipc or (dest_storage.getIpcFd() != null);
serialized_buffer.parents[serialized_len] = begin_parent;
Expand Down

0 comments on commit 65a0e14

Please sign in to comment.