@@ -1284,6 +1284,21 @@ fn start_executing_work<B: ExtraBackendMethods>(
1284
1284
// Relinquish accidentally acquired extra tokens
1285
1285
tokens. truncate ( running) ;
1286
1286
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
+
1287
1302
let msg = coordinator_receive. recv ( ) . unwrap ( ) ;
1288
1303
match * msg. downcast :: < Message < B > > ( ) . ok ( ) . unwrap ( ) {
1289
1304
// Save the token locally and the next turn of the loop will use
@@ -1358,24 +1373,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
1358
1373
assert_eq ! ( main_thread_worker_state,
1359
1374
MainThreadWorkerState :: Codegenning ) ;
1360
1375
}
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.
1370
1376
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) ;
1379
1378
match compiled_module. kind {
1380
1379
ModuleKind :: Regular => {
1381
1380
compiled_modules. push ( compiled_module) ;
@@ -1392,12 +1391,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1392
1391
}
1393
1392
Message :: NeedsLTO { result, worker_id } => {
1394
1393
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) ;
1401
1395
needs_lto. push ( result) ;
1402
1396
}
1403
1397
Message :: AddImportOnlyModule { module_data, work_product } => {
@@ -1408,6 +1402,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1408
1402
lto_import_only_modules. push ( ( module_data, work_product) ) ;
1409
1403
main_thread_worker_state = MainThreadWorkerState :: Idle ;
1410
1404
}
1405
+ // If the thread failed that means it panicked, so we abort immediately.
1411
1406
Message :: Done { result : Err ( ( ) ) , worker_id : _ } => {
1412
1407
bug ! ( "worker thread panicked" ) ;
1413
1408
}
0 commit comments