Skip to content

Commit

Permalink
Improve atomic write probability
Browse files Browse the repository at this point in the history
The previous atomic write implementation, based on disabling I/O
buffering yielded multiple 8192 byte write(2) calls for a single print
in Perl v5.36.0.
  • Loading branch information
dspinellis committed Aug 3, 2024
1 parent e7061b3 commit 3c69031
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/csmake.pl
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,10 @@ sub spy
#
my $rulesfile = "$ENV{CSCOUT_SPY_TMPDIR}/rules";
open(RULES, ">>", $rulesfile) || die "Unable to open $rulesfile: $!\n";
# Disable buffering to avoid (for POSIX-compliant filesystems) garbled output
# Use syswrite to avoid (for POSIX-compliant filesystems) garbled output
# from concurrent spy executions
my $ofh = select RULES;
$| = 1;
select $ofh;
open(RULES, ">>", $rulesfile) || die "Unable to open $rulesfile: $!\n";
# String to accumulate rules, so that they can be written with an atomic write
my $rules;
Expand Down Expand Up @@ -484,7 +481,7 @@ sub ancestor
$rules .= "END AR\n";
}

print RULES $rules;
syswrite(RULES, $rules);
close(RULES);

# Finally, execute the real ar
Expand Down Expand Up @@ -693,7 +690,7 @@ sub ancestor
$rules .= "END LINK\n";
}

print RULES $rules;
syswrite(RULES, $rules);
close(RULES);

# Finally, execute the real gcc
Expand Down Expand Up @@ -777,7 +774,7 @@ sub abs_if_exists
$rules .= "END LINK\n";
}

print RULES $rules;
syswrite(RULES, $rules);
close(RULES);

# Finally, execute the real ld
Expand Down Expand Up @@ -813,7 +810,7 @@ sub abs_if_exists
}
}

print RULES $rules;
syswrite(RULES, $rules);
close(RULES);

# Finally, execute the real mv
Expand Down Expand Up @@ -872,7 +869,7 @@ sub abs_if_exists
}
}

print RULES $rules;
syswrite(RULES, $rules);
close(RULES);

# Finally, execute the real install
Expand Down

0 comments on commit 3c69031

Please sign in to comment.