Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::thread::scope to replace crossbeam #10977

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 11 additions & 12 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<anyhow::Error> {
trace!("queue: {:#?}", self.queue);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(),
Expand Down