@@ -80,7 +80,7 @@ mod inherited_jobserver {
80
80
81
81
pub ( super ) struct JobServer {
82
82
/// Implicit token for this process which is obtained and will be
83
- /// released in parent. Since JobTokens only give back what they got,
83
+ /// released in parent. Since ` JobTokens` only give back what they got,
84
84
/// there should be at most one global implicit token in the wild.
85
85
///
86
86
/// Since Rust does not execute any `Drop` for global variables,
@@ -164,7 +164,7 @@ mod inherited_jobserver {
164
164
helper_thread : Option < HelperThread > ,
165
165
}
166
166
167
- impl < ' a > ActiveJobServer < ' a > {
167
+ impl ActiveJobServer < ' _ > {
168
168
pub ( super ) async fn acquire ( & mut self ) -> Result < JobToken , Error > {
169
169
let mut has_requested_token = false ;
170
170
@@ -233,19 +233,14 @@ mod inprocess_jobserver {
233
233
impl JobServer {
234
234
pub ( super ) fn new ( ) -> Self {
235
235
// Use `NUM_JOBS` if set (it's configured by Cargo) and otherwise
236
- // just fall back to a semi-reasonable number.
237
- //
238
- // Note that we could use `num_cpus` here but it's an extra
239
- // dependency that will almost never be used, so
240
- // it's generally not too worth it.
241
- let mut parallelism = 4 ;
242
- // TODO: Use std::thread::available_parallelism as an upper bound
243
- // when MSRV is bumped.
244
- if let Ok ( amt) = var ( "NUM_JOBS" ) {
245
- if let Ok ( amt) = amt. parse ( ) {
246
- parallelism = amt;
247
- }
248
- }
236
+ // just fall back to the number of cores on the local machine, or a reasonable
237
+ // default if that cannot be determined.
238
+
239
+ let parallelism = var ( "NUM_JOBS" )
240
+ . ok ( )
241
+ . and_then ( |j| j. parse :: < u32 > ( ) . ok ( ) )
242
+ . or_else ( || Some ( std:: thread:: available_parallelism ( ) . ok ( ) ?. get ( ) as u32 ) )
243
+ . unwrap_or ( 4 ) ;
249
244
250
245
Self ( AtomicU32 :: new ( parallelism) )
251
246
}
0 commit comments