diff --git a/wg-event-gen/Cargo.lock b/wg-event-gen/Cargo.lock index 05274a0..51f72ec 100644 --- a/wg-event-gen/Cargo.lock +++ b/wg-event-gen/Cargo.lock @@ -132,6 +132,14 @@ name = "libc" version = "0.2.47" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "num_cpus" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.27" @@ -214,6 +222,14 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "threadpool" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "time" version = "0.1.42" @@ -253,6 +269,7 @@ dependencies = [ "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "structopt-derive 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -292,6 +309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" "checksum libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)" = "48450664a984b25d5b479554c29cc04e3150c97aa4c01da5604a2d4ed9151476" +"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" "checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" @@ -302,6 +320,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" +"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" diff --git a/wg-event-gen/Cargo.toml b/wg-event-gen/Cargo.toml index b7f2272..60d7435 100644 --- a/wg-event-gen/Cargo.toml +++ b/wg-event-gen/Cargo.toml @@ -11,6 +11,7 @@ time = "0.1.42" structopt = "0.2.14" structopt-derive = "0.2.14" derive_builder = "0.7.1" +threadpool = "1.7.1" [profile.release] lto = true diff --git a/wg-event-gen/src/listener.rs b/wg-event-gen/src/listener.rs index d9d6e10..1a5d731 100644 --- a/wg-event-gen/src/listener.rs +++ b/wg-event-gen/src/listener.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; use std::process::Command; use std::thread; use std::time::SystemTime; +use threadpool::ThreadPool; pub trait EventListener { fn name(&self) -> &'static str; @@ -87,11 +88,13 @@ impl EventListener for LogListener { pub struct ScriptListener { pub script: PathBuf, + pub pool: ThreadPool, } impl ScriptListener { pub fn new(script: PathBuf) -> ScriptListener { - ScriptListener { script } + let pool = ThreadPool::new(4); + ScriptListener { script, pool } } fn peer_props<'a>(&self, peer: &'a Peer) -> String { @@ -136,7 +139,7 @@ impl ScriptListener { fn call_sub<'a>(&self, args: Vec<&'a str>) { let mut cmd = self.mkcmd(args); - thread::spawn(move || { + self.pool.execute(move || { cmd.spawn().expect("Failed to call Script hooḱ!"); }); }