Skip to content

Commit e7d8275

Browse files
andrewdavidmackenziecuviper
authored andcommitted
Use std::thread::available_parallelism() instead of num_cpus dependency
(cherry picked from commit 936093f)
1 parent 2e82ca6 commit e7d8275

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

rayon-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ name = "rayon_core"
1818

1919
# Some dependencies may not be their latest version, in order to support older rustc.
2020
[dependencies]
21-
num_cpus = "1.2"
2221
crossbeam-channel = "0.5.0"
2322
crossbeam-deque = "0.8.1"
2423
crossbeam-utils = "0.8.0"

rayon-core/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use std::fmt;
7070
use std::io;
7171
use std::marker::PhantomData;
7272
use std::str::FromStr;
73+
use std::thread;
7374

7475
#[macro_use]
7576
mod log;
@@ -496,7 +497,8 @@ impl<S> ThreadPoolBuilder<S> {
496497
.and_then(|s| usize::from_str(&s).ok())
497498
{
498499
Some(x) if x > 0 => return x,
499-
Some(x) if x == 0 => return num_cpus::get(),
500+
Some(x) if x == 0 => return thread::available_parallelism()
501+
.map(|n| n.get()).unwrap_or(1),
500502
_ => {}
501503
}
502504

@@ -506,7 +508,7 @@ impl<S> ThreadPoolBuilder<S> {
506508
.and_then(|s| usize::from_str(&s).ok())
507509
{
508510
Some(x) if x > 0 => x,
509-
_ => num_cpus::get(),
511+
_ => thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
510512
}
511513
}
512514
}

0 commit comments

Comments
 (0)