From 7a3ae058e8fdc755f267d22bd121c3ac99254740 Mon Sep 17 00:00:00 2001 From: timvisee Date: Thu, 11 Jan 2018 20:14:55 +0100 Subject: [PATCH] Make default number of threads same as CPU cores --- Cargo.lock | 1 + Cargo.toml | 1 + README.md | 2 +- src/app.rs | 3 --- src/arg_handler.rs | 7 +++---- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80d66e5..7cda8be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,6 +221,7 @@ dependencies = [ "bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 9b6f62a..782efcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ authors = ["Tim Visée "] bufstream = "0.1" clap = "2.29" image = "0.18" +num_cpus = "1.8" regex = "0.2" diff --git a/README.md b/README.md index 22cd163..74c0d15 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ OPTIONS: -h, --height Draw height (def: screen height) -x Draw X offset (def: 0) -y Draw Y offset (def: 0) - -c, --count Number of concurrent threads (def: 4) + -c, --count Number of concurrent threads (def: CPUs) -r, --fps Frames per second with multiple images (def: 1) ARGS: diff --git a/src/app.rs b/src/app.rs index 12aeb85..15c1e3e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,9 +4,6 @@ pub const APP_VERSION: &'static str = "0.1"; pub const APP_AUTHOR: &'static str = "Tim Visee "; pub const APP_ABOUT: &'static str = "A quick pixelflut client, that pwns pixelflut panels."; -// The default thread count -pub const DEFAULT_THREAD_COUNT: usize = 4; - // The default frames per second rate pub const DEFAULT_IMAGE_FPS: u32 = 1; diff --git a/src/arg_handler.rs b/src/arg_handler.rs index 7a5fee9..44a9407 100644 --- a/src/arg_handler.rs +++ b/src/arg_handler.rs @@ -1,4 +1,5 @@ extern crate clap; +extern crate num_cpus; use clap::{Arg, ArgMatches, App}; @@ -50,14 +51,12 @@ impl<'a: 'b, 'b> ArgHandler<'a> { .takes_value(true)) .arg(Arg::with_name("x") .short("x") - .long("x") .value_name("PIXELS") .help("Draw X offset (def: 0)") .display_order(4) .takes_value(true)) .arg(Arg::with_name("y") .short("y") - .long("y") .value_name("PIXELS") .help("Draw Y offset (def: 0)") .display_order(5) @@ -68,7 +67,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> { .alias("thread") .alias("threads") .value_name("COUNT") - .help("Number of concurrent threads (def: 4)") + .help("Number of concurrent threads (def: CPUs)") .display_order(6) .takes_value(true)) .arg(Arg::with_name("fps") @@ -95,7 +94,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> { /// Get the thread count. pub fn count(&self) -> usize { self.matches.value_of("count") - .unwrap_or(&format!("{}", DEFAULT_THREAD_COUNT)) + .unwrap_or(&format!("{}", num_cpus::get())) .parse::() .expect("Invalid count specified") }