Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Arc overhead #10

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,17 @@ impl Cli {
});
}

let send_clone = send.clone();
let child_pid = i32::try_from(child.id())?;
let child_was_killed = Arc::new(AtomicBool::from(false));
let child_was_killed_clone = child_was_killed.clone();
std::thread::spawn(move || {
handle_signals(
send_clone,
nix::unistd::Pid::from_raw(child_pid),
child_was_killed_clone,
)
static CHILD_WAS_KILLED: AtomicBool = AtomicBool::new(false);
std::thread::spawn({
let send = send.clone();
move || {
handle_signals(
send,
nix::unistd::Pid::from_raw(child_pid),
&CHILD_WAS_KILLED,
)
}
});

std::thread::spawn(|| watch_child(send, child));
Expand All @@ -167,7 +168,7 @@ impl Cli {
)),
MainMessage::ChildExited(exit_status) => {
if self.can_exit && exit_status.success()
|| child_was_killed.load(Ordering::SeqCst)
|| CHILD_WAS_KILLED.load(Ordering::SeqCst)
{
eprintln!("Child exited, treating as a success case");
Ok(())
Expand Down Expand Up @@ -309,7 +310,7 @@ fn watch_child(send: SendMainMessage, mut child: Child) {
fn handle_signals(
send: SendMainMessage,
child_pid: nix::unistd::Pid,
child_was_killed: Arc<AtomicBool>,
child_was_killed: &AtomicBool,
) {
let mut signals = match signal_hook::iterator::Signals::new([SIGTERM, SIGINT])
.context("Creating new Signals value")
Expand Down
Loading