]> git.lizzy.rs Git - rust.git/commitdiff
trans-scheduler: Let main thread take over for other worker.
authorMichael Woerister <michaelwoerister@posteo>
Wed, 9 Aug 2017 16:18:48 +0000 (18:18 +0200)
committerMichael Woerister <michaelwoerister@posteo>
Wed, 9 Aug 2017 16:18:48 +0000 (18:18 +0200)
src/librustc_trans/back/write.rs

index 0d5fe6c0ae95fa3dffc45dc711098e4e490c6be7..94cae37761fe2bf36cd54e6246eedb10392f2c78 100644 (file)
@@ -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 => {