@@ -1502,10 +1502,6 @@ struct parallel_processes {
1502
1502
const size_t max_processes ;
1503
1503
size_t nr_processes ;
1504
1504
1505
- get_next_task_fn get_next_task ;
1506
- start_failure_fn start_failure ;
1507
- task_finished_fn task_finished ;
1508
-
1509
1505
struct {
1510
1506
enum child_state state ;
1511
1507
struct child_process process ;
@@ -1525,21 +1521,6 @@ struct parallel_processes {
1525
1521
struct strbuf buffered_output ; /* of finished children */
1526
1522
};
1527
1523
1528
- static int default_start_failure (struct strbuf * out ,
1529
- void * pp_cb ,
1530
- void * pp_task_cb )
1531
- {
1532
- return 0 ;
1533
- }
1534
-
1535
- static int default_task_finished (int result ,
1536
- struct strbuf * out ,
1537
- void * pp_cb ,
1538
- void * pp_task_cb )
1539
- {
1540
- return 0 ;
1541
- }
1542
-
1543
1524
static void kill_children (const struct parallel_processes * pp , int signo )
1544
1525
{
1545
1526
for (size_t i = 0 ; i < pp -> max_processes ; i ++ )
@@ -1560,22 +1541,15 @@ static void pp_init(struct parallel_processes *pp,
1560
1541
const struct run_process_parallel_opts * opts )
1561
1542
{
1562
1543
const size_t n = opts -> processes ;
1563
- get_next_task_fn get_next_task = opts -> get_next_task ;
1564
- start_failure_fn start_failure = opts -> start_failure ;
1565
- task_finished_fn task_finished = opts -> task_finished ;
1566
1544
1567
1545
if (!n )
1568
1546
BUG ("you must provide a non-zero number of processes!" );
1569
1547
1570
1548
trace_printf ("run_processes_parallel: preparing to run up to %" PRIuMAX " tasks" ,
1571
1549
(uintmax_t )n );
1572
1550
1573
- if (!get_next_task )
1551
+ if (!opts -> get_next_task )
1574
1552
BUG ("you need to specify a get_next_task function" );
1575
- pp -> get_next_task = get_next_task ;
1576
-
1577
- pp -> start_failure = start_failure ? start_failure : default_start_failure ;
1578
- pp -> task_finished = task_finished ? task_finished : default_task_finished ;
1579
1553
1580
1554
CALLOC_ARRAY (pp -> children , n );
1581
1555
if (!pp -> ungroup )
@@ -1622,7 +1596,8 @@ static void pp_cleanup(struct parallel_processes *pp)
1622
1596
* <0 no new job was started, user wishes to shutdown early. Use negative code
1623
1597
* to signal the children.
1624
1598
*/
1625
- static int pp_start_one (struct parallel_processes * pp )
1599
+ static int pp_start_one (struct parallel_processes * pp ,
1600
+ const struct run_process_parallel_opts * opts )
1626
1601
{
1627
1602
size_t i ;
1628
1603
int code ;
@@ -1633,10 +1608,10 @@ static int pp_start_one(struct parallel_processes *pp)
1633
1608
if (i == pp -> max_processes )
1634
1609
BUG ("bookkeeping is hard" );
1635
1610
1636
- code = pp -> get_next_task (& pp -> children [i ].process ,
1637
- pp -> ungroup ? NULL : & pp -> children [i ].err ,
1638
- pp -> data ,
1639
- & pp -> children [i ].data );
1611
+ code = opts -> get_next_task (& pp -> children [i ].process ,
1612
+ pp -> ungroup ? NULL : & pp -> children [i ].err ,
1613
+ pp -> data ,
1614
+ & pp -> children [i ].data );
1640
1615
if (!code ) {
1641
1616
if (!pp -> ungroup ) {
1642
1617
strbuf_addbuf (& pp -> buffered_output , & pp -> children [i ].err );
@@ -1651,10 +1626,14 @@ static int pp_start_one(struct parallel_processes *pp)
1651
1626
pp -> children [i ].process .no_stdin = 1 ;
1652
1627
1653
1628
if (start_command (& pp -> children [i ].process )) {
1654
- code = pp -> start_failure (pp -> ungroup ? NULL :
1655
- & pp -> children [i ].err ,
1656
- pp -> data ,
1657
- pp -> children [i ].data );
1629
+ if (opts -> start_failure )
1630
+ code = opts -> start_failure (pp -> ungroup ? NULL :
1631
+ & pp -> children [i ].err ,
1632
+ pp -> data ,
1633
+ pp -> children [i ].data );
1634
+ else
1635
+ code = 0 ;
1636
+
1658
1637
if (!pp -> ungroup ) {
1659
1638
strbuf_addbuf (& pp -> buffered_output , & pp -> children [i ].err );
1660
1639
strbuf_reset (& pp -> children [i ].err );
@@ -1709,7 +1688,8 @@ static void pp_output(const struct parallel_processes *pp)
1709
1688
}
1710
1689
}
1711
1690
1712
- static int pp_collect_finished (struct parallel_processes * pp )
1691
+ static int pp_collect_finished (struct parallel_processes * pp ,
1692
+ const struct run_process_parallel_opts * opts )
1713
1693
{
1714
1694
int code ;
1715
1695
size_t i , n = pp -> max_processes ;
@@ -1724,9 +1704,12 @@ static int pp_collect_finished(struct parallel_processes *pp)
1724
1704
1725
1705
code = finish_command (& pp -> children [i ].process );
1726
1706
1727
- code = pp -> task_finished (code , pp -> ungroup ? NULL :
1728
- & pp -> children [i ].err , pp -> data ,
1729
- pp -> children [i ].data );
1707
+ if (opts -> task_finished )
1708
+ code = opts -> task_finished (code , pp -> ungroup ? NULL :
1709
+ & pp -> children [i ].err , pp -> data ,
1710
+ pp -> children [i ].data );
1711
+ else
1712
+ code = 0 ;
1730
1713
1731
1714
if (code )
1732
1715
result = code ;
@@ -1795,7 +1778,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
1795
1778
i < spawn_cap && !pp .shutdown &&
1796
1779
pp .nr_processes < pp .max_processes ;
1797
1780
i ++ ) {
1798
- code = pp_start_one (& pp );
1781
+ code = pp_start_one (& pp , opts );
1799
1782
if (!code )
1800
1783
continue ;
1801
1784
if (code < 0 ) {
@@ -1813,7 +1796,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
1813
1796
pp_buffer_stderr (& pp , output_timeout );
1814
1797
pp_output (& pp );
1815
1798
}
1816
- code = pp_collect_finished (& pp );
1799
+ code = pp_collect_finished (& pp , opts );
1817
1800
if (code ) {
1818
1801
pp .shutdown = 1 ;
1819
1802
if (code < 0 )
0 commit comments