Skip to content

Commit 3c6b37c

Browse files
Replace crossbeam-utils with std::thread::scope
1 parent 74414da commit 3c6b37c

File tree

3 files changed

+19
-57
lines changed

3 files changed

+19
-57
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ base64 = "0.20.0"
1313
bytes = "1"
1414
chrono = { version = "0.4", features = ["serde"] }
1515
crates-index = "0.18"
16-
crossbeam-utils = "0.8"
1716
crossbeam-channel = "0.5"
1817
csv = "1.0.2"
1918
docsrs-metadata = { git = "https://github.com/rust-lang/docs.rs/" }

src/runner/mod.rs

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use crate::experiments::{Experiment, Mode};
99
use crate::prelude::*;
1010
use crate::results::{TestResult, WriteResults};
1111
use crate::runner::worker::{DiskSpaceWatcher, Worker};
12-
use crossbeam_utils::thread::{scope, ScopedJoinHandle};
1312
use rustwide::logging::LogStorage;
1413
use rustwide::Workspace;
1514
use std::collections::HashMap;
1615
use std::sync::Mutex;
16+
use std::thread::scope;
1717
use std::time::Duration;
1818

1919
const DISK_SPACE_WATCHER_INTERVAL: Duration = Duration::from_secs(30);
@@ -107,7 +107,6 @@ pub fn run_ex<DB: WriteResults + Sync>(
107107
info!("running tasks in {} threads...", threads_count);
108108

109109
let state = RunnerState::new();
110-
111110
let workers = (0..threads_count)
112111
.map(|i| {
113112
Worker::new(
@@ -128,68 +127,33 @@ pub fn run_ex<DB: WriteResults + Sync>(
128127
&workers,
129128
);
130129

131-
let r = scope(|scope| -> Fallible<()> {
132-
let mut threads = Vec::new();
133-
134-
for worker in &workers {
135-
let join =
136-
scope
137-
.builder()
130+
scope(|scope1| {
131+
std::thread::Builder::new()
132+
.name("disk-space-watcher".into())
133+
.spawn_scoped(scope1, || {
134+
disk_watcher.run();
135+
})
136+
.unwrap();
137+
138+
scope(|scope| {
139+
for worker in &workers {
140+
std::thread::Builder::new()
138141
.name(worker.name().into())
139-
.spawn(move |_| -> Fallible<()> {
142+
.spawn_scoped(scope, move || -> Fallible<()> {
140143
match worker.run() {
141144
Ok(()) => Ok(()),
142145
Err(r) => {
143146
log::warn!("worker {} failed: {:?}", worker.name(), r);
144147
Err(r)
145148
}
146149
}
147-
})?;
148-
threads.push(join);
149-
}
150-
let disk_watcher_thread =
151-
scope
152-
.builder()
153-
.name("disk-space-watcher".into())
154-
.spawn(|_| {
155-
disk_watcher.run();
156-
Ok(())
157-
})?;
158-
159-
let clean_exit = join_threads(threads.into_iter());
160-
disk_watcher.stop();
161-
let disk_watcher_clean_exit = join_threads(std::iter::once(disk_watcher_thread));
150+
})
151+
.unwrap();
152+
}
153+
});
162154

163-
if clean_exit && disk_watcher_clean_exit {
164-
Ok(())
165-
} else {
166-
bail!("some threads returned an error");
167-
}
155+
disk_watcher.stop();
168156
});
169157

170-
match r {
171-
Ok(r) => r,
172-
Err(panic) => std::panic::resume_unwind(panic),
173-
}
174-
}
175-
176-
fn join_threads<'a, I>(iter: I) -> bool
177-
where
178-
I: Iterator<Item = ScopedJoinHandle<'a, Fallible<()>>>,
179-
{
180-
let mut clean_exit = true;
181-
for thread in iter {
182-
match thread.join() {
183-
Ok(Ok(())) => {}
184-
Ok(Err(err)) => {
185-
crate::utils::report_failure(&err);
186-
clean_exit = false;
187-
}
188-
Err(panic) => {
189-
crate::utils::report_panic(&panic);
190-
clean_exit = false;
191-
}
192-
}
193-
}
194-
clean_exit
158+
Ok(())
195159
}

0 commit comments

Comments
 (0)