@@ -1037,7 +1037,7 @@ pub(crate) enum Message<B: WriteBackendMethods> {
1037
1037
1038
1038
/// The backend has finished processing a work item for a codegen unit.
1039
1039
/// Sent from a backend worker thread.
1040
- WorkItem { result : Result < WorkItemResult < B > , Option < WorkerFatalError > > , worker_id : usize } ,
1040
+ WorkItem { result : Result < WorkItemResult < B > , Option < WorkerFatalError > > } ,
1041
1041
1042
1042
/// The frontend has finished generating something (backend IR or a
1043
1043
/// post-LTO artifact) for a codegen unit, and it should be passed to the
@@ -1355,18 +1355,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
1355
1355
// necessary. There's already optimizations in place to avoid sending work
1356
1356
// back to the coordinator if LTO isn't requested.
1357
1357
return B :: spawn_named_thread ( cgcx. time_trace , "coordinator" . to_string ( ) , move || {
1358
- let mut worker_id_counter = 0 ;
1359
- let mut free_worker_ids = Vec :: new ( ) ;
1360
- let mut get_worker_id = |free_worker_ids : & mut Vec < usize > | {
1361
- if let Some ( id) = free_worker_ids. pop ( ) {
1362
- id
1363
- } else {
1364
- let id = worker_id_counter;
1365
- worker_id_counter += 1 ;
1366
- id
1367
- }
1368
- } ;
1369
-
1370
1358
// This is where we collect codegen units that have gone all the way
1371
1359
// through codegen and LLVM.
1372
1360
let mut compiled_modules = vec ! [ ] ;
@@ -1447,12 +1435,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1447
1435
let ( item, _) =
1448
1436
work_items. pop ( ) . expect ( "queue empty - queue_full_enough() broken?" ) ;
1449
1437
main_thread_state = MainThreadState :: Lending ;
1450
- spawn_work (
1451
- & cgcx,
1452
- & mut llvm_start_time,
1453
- get_worker_id ( & mut free_worker_ids) ,
1454
- item,
1455
- ) ;
1438
+ spawn_work ( & cgcx, & mut llvm_start_time, item) ;
1456
1439
}
1457
1440
}
1458
1441
} else if codegen_state == Completed {
@@ -1521,12 +1504,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1521
1504
MainThreadState :: Idle => {
1522
1505
if let Some ( ( item, _) ) = work_items. pop ( ) {
1523
1506
main_thread_state = MainThreadState :: Lending ;
1524
- spawn_work (
1525
- & cgcx,
1526
- & mut llvm_start_time,
1527
- get_worker_id ( & mut free_worker_ids) ,
1528
- item,
1529
- ) ;
1507
+ spawn_work ( & cgcx, & mut llvm_start_time, item) ;
1530
1508
} else {
1531
1509
// There is no unstarted work, so let the main thread
1532
1510
// take over for a running worker. Otherwise the
@@ -1562,34 +1540,14 @@ fn start_executing_work<B: ExtraBackendMethods>(
1562
1540
while running_with_own_token < tokens. len ( )
1563
1541
&& let Some ( ( item, _) ) = work_items. pop ( )
1564
1542
{
1565
- spawn_work (
1566
- & cgcx,
1567
- & mut llvm_start_time,
1568
- get_worker_id ( & mut free_worker_ids) ,
1569
- item,
1570
- ) ;
1543
+ spawn_work ( & cgcx, & mut llvm_start_time, item) ;
1571
1544
running_with_own_token += 1 ;
1572
1545
}
1573
1546
}
1574
1547
1575
1548
// Relinquish accidentally acquired extra tokens.
1576
1549
tokens. truncate ( running_with_own_token) ;
1577
1550
1578
- // If a thread exits successfully then we drop a token associated
1579
- // with that worker and update our `running_with_own_token` count.
1580
- // We may later re-acquire a token to continue running more work.
1581
- // We may also not actually drop a token here if the worker was
1582
- // running with an "ephemeral token".
1583
- let mut free_worker = |worker_id| {
1584
- if main_thread_state == MainThreadState :: Lending {
1585
- main_thread_state = MainThreadState :: Idle ;
1586
- } else {
1587
- running_with_own_token -= 1 ;
1588
- }
1589
-
1590
- free_worker_ids. push ( worker_id) ;
1591
- } ;
1592
-
1593
1551
let msg = coordinator_receive. recv ( ) . unwrap ( ) ;
1594
1552
match * msg. downcast :: < Message < B > > ( ) . ok ( ) . unwrap ( ) {
1595
1553
// Save the token locally and the next turn of the loop will use
@@ -1658,8 +1616,17 @@ fn start_executing_work<B: ExtraBackendMethods>(
1658
1616
codegen_state = Aborted ;
1659
1617
}
1660
1618
1661
- Message :: WorkItem { result, worker_id } => {
1662
- free_worker ( worker_id) ;
1619
+ Message :: WorkItem { result } => {
1620
+ // If a thread exits successfully then we drop a token associated
1621
+ // with that worker and update our `running_with_own_token` count.
1622
+ // We may later re-acquire a token to continue running more work.
1623
+ // We may also not actually drop a token here if the worker was
1624
+ // running with an "ephemeral token".
1625
+ if main_thread_state == MainThreadState :: Lending {
1626
+ main_thread_state = MainThreadState :: Idle ;
1627
+ } else {
1628
+ running_with_own_token -= 1 ;
1629
+ }
1663
1630
1664
1631
match result {
1665
1632
Ok ( WorkItemResult :: Finished ( compiled_module) ) => {
@@ -1805,7 +1772,6 @@ pub(crate) struct WorkerFatalError;
1805
1772
fn spawn_work < ' a , B : ExtraBackendMethods > (
1806
1773
cgcx : & ' a CodegenContext < B > ,
1807
1774
llvm_start_time : & mut Option < VerboseTimingGuard < ' a > > ,
1808
- worker_id : usize ,
1809
1775
work : WorkItem < B > ,
1810
1776
) {
1811
1777
if cgcx. config ( work. module_kind ( ) ) . time_module && llvm_start_time. is_none ( ) {
@@ -1820,24 +1786,21 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
1820
1786
struct Bomb < B : ExtraBackendMethods > {
1821
1787
coordinator_send : Sender < Box < dyn Any + Send > > ,
1822
1788
result : Option < Result < WorkItemResult < B > , FatalError > > ,
1823
- worker_id : usize ,
1824
1789
}
1825
1790
impl < B : ExtraBackendMethods > Drop for Bomb < B > {
1826
1791
fn drop ( & mut self ) {
1827
- let worker_id = self . worker_id ;
1828
1792
let msg = match self . result . take ( ) {
1829
- Some ( Ok ( result) ) => Message :: WorkItem :: < B > { result : Ok ( result) , worker_id } ,
1793
+ Some ( Ok ( result) ) => Message :: WorkItem :: < B > { result : Ok ( result) } ,
1830
1794
Some ( Err ( FatalError ) ) => {
1831
- Message :: WorkItem :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1795
+ Message :: WorkItem :: < B > { result : Err ( Some ( WorkerFatalError ) ) }
1832
1796
}
1833
- None => Message :: WorkItem :: < B > { result : Err ( None ) , worker_id } ,
1797
+ None => Message :: WorkItem :: < B > { result : Err ( None ) } ,
1834
1798
} ;
1835
1799
drop ( self . coordinator_send . send ( Box :: new ( msg) ) ) ;
1836
1800
}
1837
1801
}
1838
1802
1839
- let mut bomb =
1840
- Bomb :: < B > { coordinator_send : cgcx. coordinator_send . clone ( ) , result : None , worker_id } ;
1803
+ let mut bomb = Bomb :: < B > { coordinator_send : cgcx. coordinator_send . clone ( ) , result : None } ;
1841
1804
1842
1805
// Execute the work itself, and if it finishes successfully then flag
1843
1806
// ourselves as a success as well.
0 commit comments