1496
GIT_CP_WAIT_CLEANUP,
1497
};
1498
1499
-int run_processes_parallel_ungroup;
1499
struct parallel_processes {
1500
void *const data;
1501
1557
}
1558
1559
static void pp_init(struct parallel_processes *pp,
1561
- get_next_task_fn get_next_task,
1562
- start_failure_fn start_failure,
1563
- task_finished_fn task_finished)
1560
+ const struct run_process_parallel_opts *opts)
1561
{
1565
- const size_t n = pp->max_processes;
1562
+ 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
1567
if (!n)
1568
BUG("you must provide a non-zero number of processes!");
1769
return result;
1770
}
1771
1772
-void run_processes_parallel(size_t n,
1773
- get_next_task_fn get_next_task,
1774
- start_failure_fn start_failure,
1775
- task_finished_fn task_finished,
1776
- void *pp_cb)
1772
+void run_processes_parallel(const struct run_process_parallel_opts *opts)
1773
{
1774
int i, code;
1775
int output_timeout = 100;
1776
int spawn_cap = 4;
1781
- int ungroup = run_processes_parallel_ungroup;
1777
struct parallel_processes pp = {
1783
- .max_processes = n,
1784
- .data = pp_cb,
1778
+ .max_processes = opts->processes,
1779
+ .data = opts->data,
1780
.buffered_output = STRBUF_INIT,
1786
- .ungroup = ungroup,
1781
+ .ungroup = opts->ungroup,
1782
};
1783
+ /* options */
1784
+ const char *tr2_category = opts->tr2_category;
1785
+ const char *tr2_label = opts->tr2_label;
1786
+ const int do_trace2 = tr2_category && tr2_label;
1787
1789
- /* unset for the next API user */
1790
- run_processes_parallel_ungroup = 0;
1788
+ if (do_trace2)
1789
+ trace2_region_enter_printf(tr2_category, tr2_label, NULL,
1790
+ "max:%d", opts->processes);
1791
1792
- pp_init(&pp, get_next_task, start_failure, task_finished);
1792
+ pp_init(&pp, opts);
1793
while (1) {
1794
for (i = 0;
1795
i < spawn_cap && !pp.shutdown &&
1806
}
1807
if (!pp.nr_processes)
1808
break;
1809
- if (ungroup) {
1809
+ if (opts->ungroup) {
1810
for (size_t i = 0; i < pp.max_processes; i++)
1811
pp.children[i].state = GIT_CP_WAIT_CLEANUP;
1812
} else {
1822
}
1823
1824
pp_cleanup(&pp);
1825
+
1826
+ if (do_trace2)
1827
+ trace2_region_leave(tr2_category, tr2_label, NULL);
1828
}
1829
1827
-void run_processes_parallel_tr2(size_t n, get_next_task_fn get_next_task,
1830
+void run_processes_parallel_tr2(size_t processes, get_next_task_fn get_next_task,
1831
start_failure_fn start_failure,
1832
task_finished_fn task_finished, void *pp_cb,
1833
const char *tr2_category, const char *tr2_label)
1834
{
1832
- trace2_region_enter_printf(tr2_category, tr2_label, NULL, "max:%d", n);
1835
+ const struct run_process_parallel_opts opts = {
1836
+ .tr2_category = tr2_category,
1837
+ .tr2_label = tr2_label,
1838
+ .processes = processes,
1839
1834
- run_processes_parallel(n, get_next_task, start_failure,
1835
- task_finished, pp_cb);
1840
+ .get_next_task = get_next_task,
1841
+ .start_failure = start_failure,
1842
+ .task_finished = task_finished,
1843
+ };
1844
1837
- trace2_region_leave(tr2_category, tr2_label, NULL);
1845
+ run_processes_parallel(&opts);
1846
}
1847
1848
int run_auto_maintenance(int quiet)