Drop threadpool dep (was spawning threads over and over)

This commit is contained in:
Matt Green 2016-10-30 12:28:11 -04:00
parent 2d7715f8d7
commit d859b4b70e
4 changed files with 18 additions and 24 deletions

7
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -10,7 +10,6 @@ extern crate log;
#[macro_use]
extern crate lazy_static;
extern crate notify;
extern crate threadpool;
#[cfg(unix)]
extern crate nix;

View File

@ -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<Process>,
}
impl ProcessReaper {
pub fn new(tx: Sender<()>) -> ProcessReaper {
let (processes_tx, processes_rx): (Sender<Process>, Receiver<Process>) = 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);
}
}