Skip to content

Commit c7e68dd

Browse files
committed
refactor: improve conditional compilation in get_pipe_open_options
- Replace multiple early returns with a single mutable variable approach - Add conditional allow(unused_mut) attribute for non-Linux platforms - Makes the code more concise while maintaining the same functionality
1 parent 5c6d90a commit c7e68dd

File tree

1 file changed

+12
-12
lines changed
  • src/run/runner/wall_time/perf

1 file changed

+12
-12
lines changed

src/run/runner/wall_time/perf/fifo.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ pub struct RunnerFifo {
2020
ctl_fifo: TokioPipeReader,
2121
}
2222

23+
fn get_pipe_open_options() -> TokioPipeOpenOptions {
24+
#[cfg_attr(not(target_os = "linux"), allow(unused_mut))]
25+
let mut options = TokioPipeOpenOptions::new();
26+
#[cfg(target_os = "linux")]
27+
options.read_write(true);
28+
options
29+
}
30+
2331
impl RunnerFifo {
2432
pub fn new() -> anyhow::Result<Self> {
2533
create_fifo(RUNNER_CTL_FIFO)?;
2634
create_fifo(RUNNER_ACK_FIFO)?;
2735

28-
let ack_fifo = TokioPipeOpenOptions::new()
29-
.read_write(true)
30-
.open_sender(RUNNER_ACK_FIFO)?;
31-
let ctl_fifo = TokioPipeOpenOptions::new()
32-
.read_write(true)
33-
.open_receiver(RUNNER_CTL_FIFO)?;
36+
let ack_fifo = get_pipe_open_options().open_sender(RUNNER_ACK_FIFO)?;
37+
let ctl_fifo = get_pipe_open_options().open_receiver(RUNNER_CTL_FIFO)?;
3438

3539
Ok(Self { ctl_fifo, ack_fifo })
3640
}
@@ -80,12 +84,8 @@ impl PerfFifo {
8084
create_fifo(&ctl_fifo_path)?;
8185
create_fifo(&ack_fifo_path)?;
8286

83-
let ack_fifo = TokioPipeOpenOptions::new()
84-
.read_write(true)
85-
.open_receiver(&ack_fifo_path)?;
86-
let ctl_fifo = TokioPipeOpenOptions::new()
87-
.read_write(true)
88-
.open_sender(&ctl_fifo_path)?;
87+
let ack_fifo = get_pipe_open_options().open_receiver(&ack_fifo_path)?;
88+
let ctl_fifo = get_pipe_open_options().open_sender(&ctl_fifo_path)?;
8989

9090
Ok(Self {
9191
ctl_fifo,

0 commit comments

Comments
 (0)