@@ -1300,12 +1300,16 @@ fn start_executing_work<B: ExtraBackendMethods>(
13001300 let mut main_thread_state = MainThreadState :: Idle ;
13011301
13021302 // How many LLVM worker threads are running while holding a Token. This
1303- // *excludes* the LLVM worker thread that the main thread is lending a
1304- // Token to (when the main thread is in the `Lending` state).
1305- // In other words, the number of LLVM threads is actually equal to
1306- // `running + if main_thread_state == Lending { 1 } else { 0 }`.
1303+ // *excludes* any that the main thread is lending a Token to.
13071304 let mut running_with_own_token = 0 ;
13081305
1306+ // How many LLVM worker threads are running in total. This *includes*
1307+ // any that the main thread is lending a Token to.
1308+ let running_with_any_token = |main_thread_state, running_with_own_token| {
1309+ running_with_own_token
1310+ + if main_thread_state == MainThreadState :: Lending { 1 } else { 0 }
1311+ } ;
1312+
13091313 let mut llvm_start_time: Option < VerboseTimingGuard < ' _ > > = None ;
13101314
13111315 // Run the message loop while there's still anything that needs message
@@ -1352,8 +1356,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
13521356 }
13531357 }
13541358 } else if codegen_state == Completed {
1355- if running_with_own_token == 0
1356- && main_thread_state == MainThreadState :: Idle
1359+ if running_with_any_token ( main_thread_state, running_with_own_token) == 0
13571360 && work_items. is_empty ( )
13581361 {
13591362 // All codegen work is done. Do we have LTO work to do?
@@ -1427,7 +1430,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14271430 // Don't queue up any more work if codegen was aborted, we're
14281431 // just waiting for our existing children to finish.
14291432 assert ! ( codegen_state == Aborted ) ;
1430- if running_with_own_token == 0 && main_thread_state != MainThreadState :: Lending {
1433+ if running_with_any_token ( main_thread_state , running_with_own_token) == 0 {
14311434 break ;
14321435 }
14331436 }
0 commit comments