Skip to content

Commit 9054e66

Browse files
committed
Fix panic in ConcurrencyLimiter when unwinding
Fixes rust-lang#1275
1 parent 244455d commit 9054e66

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/concurrency_limiter.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(super) struct ConcurrencyLimiter {
1010
helper_thread: Option<HelperThread>,
1111
state: Arc<Mutex<state::ConcurrencyLimiterState>>,
1212
available_token_condvar: Arc<Condvar>,
13+
finished: bool,
1314
}
1415

1516
impl ConcurrencyLimiter {
@@ -32,6 +33,7 @@ impl ConcurrencyLimiter {
3233
helper_thread: Some(helper_thread),
3334
state,
3435
available_token_condvar: Arc::new(Condvar::new()),
36+
finished: false,
3537
}
3638
}
3739

@@ -56,16 +58,23 @@ impl ConcurrencyLimiter {
5658
let mut state = self.state.lock().unwrap();
5759
state.job_already_done();
5860
}
59-
}
6061

61-
impl Drop for ConcurrencyLimiter {
62-
fn drop(&mut self) {
63-
//
62+
pub(crate) fn finished(mut self) {
6463
self.helper_thread.take();
6564

6665
// Assert that all jobs have finished
6766
let state = Mutex::get_mut(Arc::get_mut(&mut self.state).unwrap()).unwrap();
6867
state.assert_done();
68+
69+
self.finished = true;
70+
}
71+
}
72+
73+
impl Drop for ConcurrencyLimiter {
74+
fn drop(&mut self) {
75+
if !self.finished && !std::thread::panicking() {
76+
panic!("Forgot to call finished() on ConcurrencyLimiter");
77+
}
6978
}
7079
}
7180

src/driver/aot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl OngoingCodegen {
106106
}
107107
}
108108

109-
drop(self.concurrency_limiter);
109+
self.concurrency_limiter.finished();
110110

111111
(
112112
CodegenResults {

0 commit comments

Comments
 (0)