From d859b4b70e620aa1820513094c9575995a91733d Mon Sep 17 00:00:00 2001 From: Matt Green Date: Sun, 30 Oct 2016 12:28:11 -0400 Subject: [PATCH] Drop threadpool dep (was spawning threads over and over) --- Cargo.lock | 7 ------- Cargo.toml | 1 - src/main.rs | 1 - src/process.rs | 33 ++++++++++++++++++--------------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index de97888..d425a99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,7 +12,6 @@ dependencies = [ "mktemp 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -249,11 +248,6 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "threadpool" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "time" version = "0.1.35" @@ -350,7 +344,6 @@ dependencies = [ "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d807fd58c4181bbabed77cb3b891ba9748241a552bcc5be698faaebefc54f46e" "checksum term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7f5f3f71b0040cecc71af239414c23fd3c73570f5ff54cf50e03cef637f2a0" -"checksum threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "59f6d3eff89920113dac9db44dde461d71d01e88a5b57b258a0466c32b5d7fe1" "checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af" "checksum unicode-segmentation 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b905d0fc2a1f0befd86b0e72e31d1787944efef9d38b9358a9e92a69757f7e3b" "checksum unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d6722facc10989f63ee0e20a83cd4e1714a9ae11529403ac7e0afd069abc39e" diff --git a/Cargo.toml b/Cargo.toml index cfa78dc..841f465 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ lazy_static = "0.2.1" libc = "0.2.16" log = "0.3.6" notify = "2.6.3" -threadpool = "1.3.2" [dev-dependencies] mktemp = "0.3.1" diff --git a/src/main.rs b/src/main.rs index 19e98f1..5e82756 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ extern crate log; #[macro_use] extern crate lazy_static; extern crate notify; -extern crate threadpool; #[cfg(unix)] extern crate nix; diff --git a/src/process.rs b/src/process.rs index 1822117..6b95ed4 100644 --- a/src/process.rs +++ b/src/process.rs @@ -1,10 +1,9 @@ -use threadpool::ThreadPool; - use std::cell::RefCell; use std::collections::{BTreeMap, VecDeque}; use std::path::{Component, PathBuf}; use std::rc::Rc; -use std::sync::mpsc::Sender; +use std::sync::mpsc::{channel, Receiver, Sender}; +use std::thread; pub use self::imp::*; @@ -178,26 +177,30 @@ mod imp { /// On Windows, we don't have SIGCHLD, and even if we did, we'd still need /// to relay that over a channel. pub struct ProcessReaper { - pool: ThreadPool, - tx: Sender<()>, + processes_tx: Sender, } impl ProcessReaper { pub fn new(tx: Sender<()>) -> ProcessReaper { + let (processes_tx, processes_rx): (Sender, Receiver) = channel(); + + thread::spawn(move || { + loop { + while let Ok(mut process) = processes_rx.recv() { + process.wait(); + + let _ = tx.send(()); + } + } + }); + ProcessReaper { - pool: ThreadPool::new(1), - tx: tx, + processes_tx: processes_tx } } - pub fn wait_process(&self, mut process: imp::Process) { - let tx = self.tx.clone(); - - self.pool.execute(move || { - process.wait(); - - let _ = tx.send(()); - }); + pub fn wait_process(&self, process: imp::Process) { + let _ = self.processes_tx.send(process); } }