@@ -1284,6 +1284,21 @@ fn start_executing_work<B: ExtraBackendMethods>(
12841284 // Relinquish accidentally acquired extra tokens
12851285 tokens. truncate ( running) ;
12861286
1287+ // If a thread exits successfully then we drop a token associated
1288+ // with that worker and update our `running` count. We may later
1289+ // re-acquire a token to continue running more work. We may also not
1290+ // actually drop a token here if the worker was running with an
1291+ // "ephemeral token"
1292+ let mut free_worker = |worker_id| {
1293+ if main_thread_worker_state == MainThreadWorkerState :: LLVMing {
1294+ main_thread_worker_state = MainThreadWorkerState :: Idle ;
1295+ } else {
1296+ running -= 1 ;
1297+ }
1298+
1299+ free_worker_ids. push ( worker_id) ;
1300+ } ;
1301+
12871302 let msg = coordinator_receive. recv ( ) . unwrap ( ) ;
12881303 match * msg. downcast :: < Message < B > > ( ) . ok ( ) . unwrap ( ) {
12891304 // Save the token locally and the next turn of the loop will use
@@ -1358,24 +1373,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
13581373 assert_eq ! ( main_thread_worker_state,
13591374 MainThreadWorkerState :: Codegenning ) ;
13601375 }
1361-
1362- // If a thread exits successfully then we drop a token associated
1363- // with that worker and update our `running` count. We may later
1364- // re-acquire a token to continue running more work. We may also not
1365- // actually drop a token here if the worker was running with an
1366- // "ephemeral token"
1367- //
1368- // Note that if the thread failed that means it panicked, so we
1369- // abort immediately.
13701376 Message :: Done { result : Ok ( compiled_module) , worker_id } => {
1371- if main_thread_worker_state == MainThreadWorkerState :: LLVMing {
1372- main_thread_worker_state = MainThreadWorkerState :: Idle ;
1373- } else {
1374- running -= 1 ;
1375- }
1376-
1377- free_worker_ids. push ( worker_id) ;
1378-
1377+ free_worker ( worker_id) ;
13791378 match compiled_module. kind {
13801379 ModuleKind :: Regular => {
13811380 compiled_modules. push ( compiled_module) ;
@@ -1392,12 +1391,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
13921391 }
13931392 Message :: NeedsLTO { result, worker_id } => {
13941393 assert ! ( !started_lto) ;
1395- if main_thread_worker_state == MainThreadWorkerState :: LLVMing {
1396- main_thread_worker_state = MainThreadWorkerState :: Idle ;
1397- } else {
1398- running -= 1 ;
1399- }
1400- free_worker_ids. push ( worker_id) ;
1394+ free_worker ( worker_id) ;
14011395 needs_lto. push ( result) ;
14021396 }
14031397 Message :: AddImportOnlyModule { module_data, work_product } => {
@@ -1408,6 +1402,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14081402 lto_import_only_modules. push ( ( module_data, work_product) ) ;
14091403 main_thread_worker_state = MainThreadWorkerState :: Idle ;
14101404 }
1405+ // If the thread failed that means it panicked, so we abort immediately.
14111406 Message :: Done { result : Err ( ( ) ) , worker_id : _ } => {
14121407 bug ! ( "worker thread panicked" ) ;
14131408 }
0 commit comments