Skip to content

Commit 5620afc

Browse files
committed
poll tidy threads for completion before waiting
1 parent f7bfc48 commit 5620afc

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/tools/tidy/src/main.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,26 @@ fn main() {
3535

3636
let bad = std::sync::Arc::new(AtomicBool::new(false));
3737

38+
let drain_handles = |handles: &mut VecDeque<ScopedJoinHandle<'_, ()>>| {
39+
// poll all threads for completion before awaiting the oldest one
40+
for i in (0..handles.len()).rev() {
41+
if handles[i].is_finished() {
42+
handles.swap_remove_back(i).unwrap().join().unwrap();
43+
}
44+
}
45+
46+
while handles.len() >= concurrency.get() {
47+
handles.pop_front().unwrap().join().unwrap();
48+
}
49+
};
50+
3851
scope(|s| {
3952
let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
4053
VecDeque::with_capacity(concurrency.get());
4154

4255
macro_rules! check {
4356
($p:ident $(, $args:expr)* ) => {
44-
while handles.len() >= concurrency.get() {
45-
handles.pop_front().unwrap().join().unwrap();
46-
}
57+
drain_handles(&mut handles);
4758

4859
let handle = s.spawn(|| {
4960
let mut flag = false;
@@ -97,9 +108,8 @@ fn main() {
97108
check!(alphabetical, &library_path);
98109

99110
let collected = {
100-
while handles.len() >= concurrency.get() {
101-
handles.pop_front().unwrap().join().unwrap();
102-
}
111+
drain_handles(&mut handles);
112+
103113
let mut flag = false;
104114
let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
105115
if flag {

0 commit comments

Comments
 (0)