about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2022-09-02 09:34:37 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2022-09-02 09:34:41 +0000
commit9054e66703dbcac8b7ba12d2ebceeecdb676ec5a (patch)
tree4ff7673182a730e893cd6c28d64dfb7d9f0377fc /src
parent244455d8e3137f3bd3e2ee6a49ebb787e7d7f792 (diff)
downloadrust-9054e66703dbcac8b7ba12d2ebceeecdb676ec5a.tar.gz
rust-9054e66703dbcac8b7ba12d2ebceeecdb676ec5a.zip
Fix panic in ConcurrencyLimiter when unwinding
Fixes #1275
Diffstat (limited to 'src')
-rw-r--r--src/concurrency_limiter.rs17
-rw-r--r--src/driver/aot.rs2
2 files changed, 14 insertions, 5 deletions
diff --git a/src/concurrency_limiter.rs b/src/concurrency_limiter.rs
index dfde9792046..f855e20e0a1 100644
--- a/src/concurrency_limiter.rs
+++ b/src/concurrency_limiter.rs
@@ -10,6 +10,7 @@ pub(super) struct ConcurrencyLimiter {
     helper_thread: Option<HelperThread>,
     state: Arc<Mutex<state::ConcurrencyLimiterState>>,
     available_token_condvar: Arc<Condvar>,
+    finished: bool,
 }
 
 impl ConcurrencyLimiter {
@@ -32,6 +33,7 @@ impl ConcurrencyLimiter {
             helper_thread: Some(helper_thread),
             state,
             available_token_condvar: Arc::new(Condvar::new()),
+            finished: false,
         }
     }
 
@@ -56,16 +58,23 @@ impl ConcurrencyLimiter {
         let mut state = self.state.lock().unwrap();
         state.job_already_done();
     }
-}
 
-impl Drop for ConcurrencyLimiter {
-    fn drop(&mut self) {
-        //
+    pub(crate) fn finished(mut self) {
         self.helper_thread.take();
 
         // Assert that all jobs have finished
         let state = Mutex::get_mut(Arc::get_mut(&mut self.state).unwrap()).unwrap();
         state.assert_done();
+
+        self.finished = true;
+    }
+}
+
+impl Drop for ConcurrencyLimiter {
+    fn drop(&mut self) {
+        if !self.finished && !std::thread::panicking() {
+            panic!("Forgot to call finished() on ConcurrencyLimiter");
+        }
     }
 }
 
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index 8eabe1cbcb1..f873561c171 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -106,7 +106,7 @@ impl OngoingCodegen {
             }
         }
 
-        drop(self.concurrency_limiter);
+        self.concurrency_limiter.finished();
 
         (
             CodegenResults {