Skip to content

Commit 9bc953e

Browse files
committed
chore: replace num_cpu with available_parallelism
Signed-off-by: tison <[email protected]>
1 parent 660f76f commit 9bc953e

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

futures-executor/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ Executors for asynchronous tasks based on the futures-rs library.
1313
[features]
1414
default = ["std"]
1515
std = ["futures-core/std", "futures-task/std", "futures-util/std"]
16-
thread-pool = ["std", "num_cpus"]
16+
thread-pool = ["std"]
1717

1818
[dependencies]
1919
futures-core = { path = "../futures-core", version = "=1.0.0-alpha.0", default-features = false }
2020
futures-task = { path = "../futures-task", version = "=0.4.0-alpha.0", default-features = false }
2121
futures-util = { path = "../futures-util", version = "=0.4.0-alpha.0", default-features = false }
22-
num_cpus = { version = "1.8.0", optional = true }
2322

2423
[dev-dependencies]
2524
futures = { path = "../futures", features = ["thread-pool"] }

futures-executor/src/thread_pool.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use futures_task::{waker_ref, ArcWake};
66
use futures_task::{FutureObj, Spawn, SpawnError};
77
use futures_util::future::FutureExt;
88
use std::boxed::Box;
9-
use std::cmp;
109
use std::fmt;
1110
use std::format;
1211
use std::io;
@@ -190,13 +189,8 @@ impl ThreadPoolBuilder {
190189
///
191190
/// See the other methods on this type for details on the defaults.
192191
pub fn new() -> Self {
193-
Self {
194-
pool_size: cmp::max(1, num_cpus::get()),
195-
stack_size: 0,
196-
name_prefix: None,
197-
after_start: None,
198-
before_stop: None,
199-
}
192+
let pool_size = thread::available_parallelism().map_or(1, |p| p.get());
193+
Self { pool_size, stack_size: 0, name_prefix: None, after_start: None, before_stop: None }
200194
}
201195

202196
/// Set size of a future ThreadPool

0 commit comments

Comments
 (0)