about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2022-11-22 00:30:05 +0100
committerThe 8472 <git@infinite-source.de>2022-12-17 14:32:13 +0100
commit5620afc4e088beb299dfdcc3c3a903ac1f80cc9f (patch)
tree4b83b4ef63d914a3c43a9da645dd00fa8490c553 /src
parentf7bfc4879390117e850da74ad73eb9f9df588350 (diff)
downloadrust-5620afc4e088beb299dfdcc3c3a903ac1f80cc9f.tar.gz
rust-5620afc4e088beb299dfdcc3c3a903ac1f80cc9f.zip
poll tidy threads for completion before waiting
Diffstat (limited to 'src')
-rw-r--r--src/tools/tidy/src/main.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index b0b11cafca5..6714c63ee62 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -35,15 +35,26 @@ fn main() {
 
     let bad = std::sync::Arc::new(AtomicBool::new(false));
 
+    let drain_handles = |handles: &mut VecDeque<ScopedJoinHandle<'_, ()>>| {
+        // poll all threads for completion before awaiting the oldest one
+        for i in (0..handles.len()).rev() {
+            if handles[i].is_finished() {
+                handles.swap_remove_back(i).unwrap().join().unwrap();
+            }
+        }
+
+        while handles.len() >= concurrency.get() {
+            handles.pop_front().unwrap().join().unwrap();
+        }
+    };
+
     scope(|s| {
         let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
             VecDeque::with_capacity(concurrency.get());
 
         macro_rules! check {
             ($p:ident $(, $args:expr)* ) => {
-                while handles.len() >= concurrency.get() {
-                    handles.pop_front().unwrap().join().unwrap();
-                }
+                drain_handles(&mut handles);
 
                 let handle = s.spawn(|| {
                     let mut flag = false;
@@ -97,9 +108,8 @@ fn main() {
         check!(alphabetical, &library_path);
 
         let collected = {
-            while handles.len() >= concurrency.get() {
-                handles.pop_front().unwrap().join().unwrap();
-            }
+            drain_handles(&mut handles);
+
             let mut flag = false;
             let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
             if flag {