From 33497512a8a95b9fb885a43cc2666ee00a85407b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 11 Aug 2022 23:11:37 +0100 Subject: [PATCH] Use std::thread::scope to replace crossbeam --- Cargo.toml | 1 - src/cargo/core/compiler/job_queue.rs | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3f183f481f1..e63503cdd0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ bytesize = "1.0" cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" } cargo-util = { path = "crates/cargo-util", version = "0.2.1" } crates-io = { path = "crates/crates-io", version = "0.34.0" } -crossbeam-utils = "0.8" curl = { version = "0.4.43", features = ["http2"] } curl-sys = "0.4.55" env_logger = "0.9.0" diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index a63949b69d1..358b6258737 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -55,11 +55,11 @@ use std::fmt::Write as _; use std::io; use std::marker; use std::sync::Arc; +use std::thread::{self, Scope}; use std::time::Duration; use anyhow::{format_err, Context as _}; use cargo_util::ProcessBuilder; -use crossbeam_utils::thread::Scope; use jobserver::{Acquired, Client, HelperThread}; use log::{debug, trace}; use semver::Version; @@ -556,22 +556,21 @@ impl<'cfg> JobQueue<'cfg> { .take() .map(move |srv| srv.start(move |msg| messages.push(Message::FixDiagnostic(msg)))); - crossbeam_utils::thread::scope(move |scope| { - match state.drain_the_queue(cx, plan, scope, &helper) { + thread::scope( + move |scope| match state.drain_the_queue(cx, plan, scope, &helper) { Some(err) => Err(err), None => Ok(()), - } - }) - .expect("child threads shouldn't panic") + }, + ) } } impl<'cfg> DrainState<'cfg> { - fn spawn_work_if_possible( + fn spawn_work_if_possible<'s>( &mut self, cx: &mut Context<'_, '_>, jobserver_helper: &HelperThread, - scope: &Scope<'_>, + scope: &'s Scope<'s, '_>, ) -> CargoResult<()> { // Dequeue as much work as we can, learning about everything // possible that can run. Note that this is also the point where we @@ -807,11 +806,11 @@ impl<'cfg> DrainState<'cfg> { /// /// This returns an Option to prevent the use of `?` on `Result` types /// because it is important for the loop to carefully handle errors. - fn drain_the_queue( + fn drain_the_queue<'s>( mut self, cx: &mut Context<'_, '_>, plan: &mut BuildPlan, - scope: &Scope<'_>, + scope: &'s Scope<'s, '_>, jobserver_helper: &HelperThread, ) -> Option { trace!("queue: {:#?}", self.queue); @@ -997,7 +996,7 @@ impl<'cfg> DrainState<'cfg> { /// /// Fresh jobs block until finished (which should be very fast!), Dirty /// jobs will spawn a thread in the background and return immediately. - fn run(&mut self, unit: &Unit, job: Job, cx: &Context<'_, '_>, scope: &Scope<'_>) { + fn run<'s>(&mut self, unit: &Unit, job: Job, cx: &Context<'_, '_>, scope: &'s Scope<'s, '_>) { let id = JobId(self.next_id); self.next_id = self.next_id.checked_add(1).unwrap(); @@ -1072,7 +1071,7 @@ impl<'cfg> DrainState<'cfg> { } Freshness::Dirty => { self.timings.add_dirty(); - scope.spawn(move |_| { + scope.spawn(move || { doit(JobState { id, messages: messages.clone(),