Skip to content

Commit 65a0e14

Browse files
committed
std.Progress: relax some of the atomic orderings
Generates better machine code, particularly on ARM
1 parent 5bdfe22 commit 65a0e14

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/std/Progress.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)