From 07149e03f45194a8fdb12c616c1f221d5186e1e5 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 9 Aug 2017 18:18:48 +0200 Subject: [PATCH] trans-scheduler: Let main thread take over for other worker. --- src/librustc_trans/back/write.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 0d5fe6c0ae95..94cae37761fe 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -1356,6 +1356,16 @@ fn start_executing_work(sess: &Session, maybe_start_llvm_timer(&item, &mut llvm_start_time); main_thread_worker_state = MainThreadWorkerState::LLVMing; spawn_work(cgcx, item); + } else { + // There is no unstarted work, so let the main thread + // take over for a running worker. Otherwise the + // implicit token would just go to waste. + // We reduce the `running` counter by one. The + // `tokens.truncate()` below will take care of + // giving the Token back. + debug_assert!(running > 0); + running -= 1; + main_thread_worker_state = MainThreadWorkerState::LLVMing; } } MainThreadWorkerState::Translating => {