Skip to content

Commit efd4ca3

Browse files
committed
Auto merge of #10977 - weihanglo:std-thread-scope, r=epage
Use `std::thread::scope` to replace crossbeam Drop one dependency as `std::thread::Scope` got stabilized in 1.63. Haven't done any benchmark. (Should we?)
2 parents 4fe9b13 + 3349751 commit efd4ca3

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ bytesize = "1.0"
2121
cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" }
2222
cargo-util = { path = "crates/cargo-util", version = "0.2.1" }
2323
crates-io = { path = "crates/crates-io", version = "0.34.0" }
24-
crossbeam-utils = "0.8"
2524
curl = { version = "0.4.43", features = ["http2"] }
2625
curl-sys = "0.4.55"
2726
env_logger = "0.9.0"

src/cargo/core/compiler/job_queue.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ use std::fmt::Write as _;
5555
use std::io;
5656
use std::marker;
5757
use std::sync::Arc;
58+
use std::thread::{self, Scope};
5859
use std::time::Duration;
5960

6061
use anyhow::{format_err, Context as _};
6162
use cargo_util::ProcessBuilder;
62-
use crossbeam_utils::thread::Scope;
6363
use jobserver::{Acquired, Client, HelperThread};
6464
use log::{debug, trace};
6565
use semver::Version;
@@ -556,22 +556,21 @@ impl<'cfg> JobQueue<'cfg> {
556556
.take()
557557
.map(move |srv| srv.start(move |msg| messages.push(Message::FixDiagnostic(msg))));
558558

559-
crossbeam_utils::thread::scope(move |scope| {
560-
match state.drain_the_queue(cx, plan, scope, &helper) {
559+
thread::scope(
560+
move |scope| match state.drain_the_queue(cx, plan, scope, &helper) {
561561
Some(err) => Err(err),
562562
None => Ok(()),
563-
}
564-
})
565-
.expect("child threads shouldn't panic")
563+
},
564+
)
566565
}
567566
}
568567

569568
impl<'cfg> DrainState<'cfg> {
570-
fn spawn_work_if_possible(
569+
fn spawn_work_if_possible<'s>(
571570
&mut self,
572571
cx: &mut Context<'_, '_>,
573572
jobserver_helper: &HelperThread,
574-
scope: &Scope<'_>,
573+
scope: &'s Scope<'s, '_>,
575574
) -> CargoResult<()> {
576575
// Dequeue as much work as we can, learning about everything
577576
// possible that can run. Note that this is also the point where we
@@ -807,11 +806,11 @@ impl<'cfg> DrainState<'cfg> {
807806
///
808807
/// This returns an Option to prevent the use of `?` on `Result` types
809808
/// because it is important for the loop to carefully handle errors.
810-
fn drain_the_queue(
809+
fn drain_the_queue<'s>(
811810
mut self,
812811
cx: &mut Context<'_, '_>,
813812
plan: &mut BuildPlan,
814-
scope: &Scope<'_>,
813+
scope: &'s Scope<'s, '_>,
815814
jobserver_helper: &HelperThread,
816815
) -> Option<anyhow::Error> {
817816
trace!("queue: {:#?}", self.queue);
@@ -997,7 +996,7 @@ impl<'cfg> DrainState<'cfg> {
997996
///
998997
/// Fresh jobs block until finished (which should be very fast!), Dirty
999998
/// jobs will spawn a thread in the background and return immediately.
1000-
fn run(&mut self, unit: &Unit, job: Job, cx: &Context<'_, '_>, scope: &Scope<'_>) {
999+
fn run<'s>(&mut self, unit: &Unit, job: Job, cx: &Context<'_, '_>, scope: &'s Scope<'s, '_>) {
10011000
let id = JobId(self.next_id);
10021001
self.next_id = self.next_id.checked_add(1).unwrap();
10031002

@@ -1072,7 +1071,7 @@ impl<'cfg> DrainState<'cfg> {
10721071
}
10731072
Freshness::Dirty => {
10741073
self.timings.add_dirty();
1075-
scope.spawn(move |_| {
1074+
scope.spawn(move || {
10761075
doit(JobState {
10771076
id,
10781077
messages: messages.clone(),

0 commit comments

Comments
 (0)