Skip to content

Commit 0b0ab95

Browse files
avargitster
authored andcommitted
run-command.c: remove "max_processes", add "const" to signal() handler
As with the *_fn members removed in a preceding commit, let's not copy the "processes" member of the "struct run_process_parallel_opts" over to the "struct parallel_processes". In this case we need the number of processes for the kill_children() function, which will be called from a signal handler. To do that adjust this code added in c553c72 (run-command: add an asynchronous parallel child processor, 2015-12-15) so that we use a dedicated "struct parallel_processes_for_signal" for passing data to the signal handler, in addition to the "struct parallel_process" it'll now have access to our "opts" variable. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1610ee commit 0b0ab95

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

run-command.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,6 @@ enum child_state {
14971497
};
14981498

14991499
struct parallel_processes {
1500-
const size_t max_processes;
15011500
size_t nr_processes;
15021501

15031502
struct {
@@ -1518,24 +1517,38 @@ struct parallel_processes {
15181517
struct strbuf buffered_output; /* of finished children */
15191518
};
15201519

1521-
static void kill_children(const struct parallel_processes *pp, int signo)
1520+
struct parallel_processes_for_signal {
1521+
const struct run_process_parallel_opts *opts;
1522+
const struct parallel_processes *pp;
1523+
};
1524+
1525+
static void kill_children(const struct parallel_processes *pp,
1526+
const struct run_process_parallel_opts *opts,
1527+
int signo)
15221528
{
1523-
for (size_t i = 0; i < pp->max_processes; i++)
1529+
for (size_t i = 0; i < opts->processes; i++)
15241530
if (pp->children[i].state == GIT_CP_WORKING)
15251531
kill(pp->children[i].process.pid, signo);
15261532
}
15271533

1528-
static struct parallel_processes *pp_for_signal;
1534+
static void kill_children_signal(const struct parallel_processes_for_signal *pp_sig,
1535+
int signo)
1536+
{
1537+
kill_children(pp_sig->pp, pp_sig->opts, signo);
1538+
}
1539+
1540+
static struct parallel_processes_for_signal *pp_for_signal;
15291541

15301542
static void handle_children_on_signal(int signo)
15311543
{
1532-
kill_children(pp_for_signal, signo);
1544+
kill_children_signal(pp_for_signal, signo);
15331545
sigchain_pop(signo);
15341546
raise(signo);
15351547
}
15361548

15371549
static void pp_init(struct parallel_processes *pp,
1538-
const struct run_process_parallel_opts *opts)
1550+
const struct run_process_parallel_opts *opts,
1551+
struct parallel_processes_for_signal *pp_sig)
15391552
{
15401553
const size_t n = opts->processes;
15411554

@@ -1561,7 +1574,9 @@ static void pp_init(struct parallel_processes *pp,
15611574
}
15621575
}
15631576

1564-
pp_for_signal = pp;
1577+
pp_sig->pp = pp;
1578+
pp_sig->opts = opts;
1579+
pp_for_signal = pp_sig;
15651580
sigchain_push_common(handle_children_on_signal);
15661581
}
15671582

@@ -1759,8 +1774,8 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
17591774
int i, code;
17601775
int output_timeout = 100;
17611776
int spawn_cap = 4;
1777+
struct parallel_processes_for_signal pp_sig;
17621778
struct parallel_processes pp = {
1763-
.max_processes = opts->processes,
17641779
.buffered_output = STRBUF_INIT,
17651780
};
17661781
/* options */
@@ -1772,7 +1787,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
17721787
trace2_region_enter_printf(tr2_category, tr2_label, NULL,
17731788
"max:%d", opts->processes);
17741789

1775-
pp_init(&pp, opts);
1790+
pp_init(&pp, opts, &pp_sig);
17761791
while (1) {
17771792
for (i = 0;
17781793
i < spawn_cap && !pp.shutdown &&
@@ -1783,7 +1798,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
17831798
continue;
17841799
if (code < 0) {
17851800
pp.shutdown = 1;
1786-
kill_children(&pp, -code);
1801+
kill_children(&pp, opts, -code);
17871802
}
17881803
break;
17891804
}
@@ -1800,7 +1815,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
18001815
if (code) {
18011816
pp.shutdown = 1;
18021817
if (code < 0)
1803-
kill_children(&pp, -code);
1818+
kill_children(&pp, opts,-code);
18041819
}
18051820
}
18061821

0 commit comments

Comments
 (0)