authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:54:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:49-07:00
log65a0e14e4f1dee68906b4a380cdb1d8517fd88ea
tree658c5380e1afe38e861e2b900aa96b89222e2b4c
parent5bdfe22092716d0e590979a678a3f5bf715439e9

std.Progress: relax some of the atomic orderings

Generates better machine code, particularly on ARM

1 files changed, 6 insertions(+), 6 deletions(-)

lib/std/Progress.zig+6-6
......@@ -104,8 +104,8 @@ pub const Node = struct {
104104 // `estimated_total_count` max int indicates the special state that
105105 // causes `completed_count` to be treated as a file descriptor, so
106106 // the order here matters.
107 @atomicStore(u32, &s.completed_count, integer, .seq_cst);
108 @atomicStore(u32, &s.estimated_total_count, std.math.maxInt(u32), .seq_cst);
107 @atomicStore(u32, &s.completed_count, integer, .monotonic);
108 @atomicStore(u32, &s.estimated_total_count, std.math.maxInt(u32), .release);
109109 }
110110
111111 /// Not thread-safe.
......@@ -590,13 +590,13 @@ fn serialize(serialized_buffer: *Serialized.Buffer) Serialized {
590590 const node_parents = global_progress.node_parents[0..end_index];
591591 const node_storage = global_progress.node_storage[0..end_index];
592592 for (node_parents, node_storage, 0..) |*parent_ptr, *storage_ptr, i| {
593 var begin_parent = @atomicLoad(Node.Parent, parent_ptr, .seq_cst);
593 var begin_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire);
594594 while (begin_parent != .unused) {
595595 const dest_storage = &serialized_buffer.storage[serialized_len];
596596 @memcpy(&dest_storage.name, &storage_ptr.name);
597 dest_storage.completed_count = @atomicLoad(u32, &storage_ptr.completed_count, .seq_cst);
598 dest_storage.estimated_total_count = @atomicLoad(u32, &storage_ptr.estimated_total_count, .seq_cst);
599 const end_parent = @atomicLoad(Node.Parent, parent_ptr, .seq_cst);
597 dest_storage.estimated_total_count = @atomicLoad(u32, &storage_ptr.estimated_total_count, .acquire);
598 dest_storage.completed_count = @atomicLoad(u32, &storage_ptr.completed_count, .monotonic);
599 const end_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire);
600600 if (begin_parent == end_parent) {
601601 any_ipc = any_ipc or (dest_storage.getIpcFd() != null);
602602 serialized_buffer.parents[serialized_len] = begin_parent;