mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
chore: replace num_cpus with available_parallelism (#6709)
This commit is contained in:
@@ -12,7 +12,6 @@ tokio = { version = "1.5.0", path = "../tokio", features = ["full"] }
|
|||||||
criterion = "0.5.1"
|
criterion = "0.5.1"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
rand_chacha = "0.3"
|
rand_chacha = "0.3"
|
||||||
num_cpus = "1.16.0"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-util = { version = "0.7.0", path = "../tokio-util", features = ["full"] }
|
tokio-util = { version = "0.7.0", path = "../tokio-util", features = ["full"] }
|
||||||
|
|||||||
+1
-5
@@ -71,10 +71,7 @@ process = [
|
|||||||
]
|
]
|
||||||
# Includes basic task execution capabilities
|
# Includes basic task execution capabilities
|
||||||
rt = []
|
rt = []
|
||||||
rt-multi-thread = [
|
rt-multi-thread = ["rt"]
|
||||||
"num_cpus",
|
|
||||||
"rt",
|
|
||||||
]
|
|
||||||
signal = [
|
signal = [
|
||||||
"libc",
|
"libc",
|
||||||
"mio/os-poll",
|
"mio/os-poll",
|
||||||
@@ -96,7 +93,6 @@ pin-project-lite = "0.2.11"
|
|||||||
# Everything else is optional...
|
# Everything else is optional...
|
||||||
bytes = { version = "1.0.0", optional = true }
|
bytes = { version = "1.0.0", optional = true }
|
||||||
mio = { version = "0.8.9", optional = true, default-features = false }
|
mio = { version = "0.8.9", optional = true, default-features = false }
|
||||||
num_cpus = { version = "1.8.0", optional = true }
|
|
||||||
parking_lot = { version = "0.12.0", optional = true }
|
parking_lot = { version = "0.12.0", optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ pub(crate) mod sync {
|
|||||||
pub(crate) mod sys {
|
pub(crate) mod sys {
|
||||||
#[cfg(feature = "rt-multi-thread")]
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
pub(crate) fn num_cpus() -> usize {
|
pub(crate) fn num_cpus() -> usize {
|
||||||
|
use std::num::NonZeroUsize;
|
||||||
|
|
||||||
const ENV_WORKER_THREADS: &str = "TOKIO_WORKER_THREADS";
|
const ENV_WORKER_THREADS: &str = "TOKIO_WORKER_THREADS";
|
||||||
|
|
||||||
match std::env::var(ENV_WORKER_THREADS) {
|
match std::env::var(ENV_WORKER_THREADS) {
|
||||||
@@ -97,7 +99,9 @@ pub(crate) mod sys {
|
|||||||
assert!(n > 0, "\"{}\" cannot be set to 0", ENV_WORKER_THREADS);
|
assert!(n > 0, "\"{}\" cannot be set to 0", ENV_WORKER_THREADS);
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
Err(std::env::VarError::NotPresent) => usize::max(1, num_cpus::get()),
|
Err(std::env::VarError::NotPresent) => {
|
||||||
|
std::thread::available_parallelism().map_or(1, NonZeroUsize::get)
|
||||||
|
}
|
||||||
Err(std::env::VarError::NotUnicode(e)) => {
|
Err(std::env::VarError::NotUnicode(e)) => {
|
||||||
panic!(
|
panic!(
|
||||||
"\"{}\" must be valid unicode, error: {:?}",
|
"\"{}\" must be valid unicode, error: {:?}",
|
||||||
|
|||||||
Reference in New Issue
Block a user