Skip to content

Commit 5d6d5cb

Browse files
oech3sylvestre
authored andcommitted
cat: don't lock stdout before splice()
1 parent 9ebeacb commit 5d6d5cb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/uu/cat/src/cat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,17 @@ fn get_input_type(path: &OsString) -> CatResult<InputType> {
478478
/// simple memory copy.
479479
fn write_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
480480
let stdout = io::stdout();
481-
let mut stdout_lock = stdout.lock();
482481
#[cfg(any(target_os = "linux", target_os = "android"))]
483482
{
484483
// If we're on Linux or Android, try to use the splice() system call
485484
// for faster writing. If it works, we're done.
486-
if !splice::write_fast_using_splice(handle, &stdout_lock)? {
485+
if !splice::write_fast_using_splice(handle, &stdout)? {
487486
return Ok(());
488487
}
489488
}
490489
// If we're not on Linux or Android, or the splice() call failed,
491490
// fall back on slower writing.
491+
let mut stdout_lock = stdout.lock();
492492
let mut buf = [0; 1024 * 64];
493493
loop {
494494
match handle.reader.read(&mut buf) {

0 commit comments

Comments
 (0)