* [committed] Factor out wait_child_exit
@ 2021-03-27 12:56 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-27 12:56 UTC (permalink / raw)
To: dwz, jakub, mark
Hi,
Factor out new function wait_child_exit out of dwz_files_1.
Committed to trunk.
Thanks,
- Tom
Factor out wait_child_exit
2021-03-27 Tom de Vries <tdevries@suse.de>
* dwz.c (wait_child_exit): New function, factored out of ...
(dwz_files_1): ... here.
---
dwz.c | 38 ++++++++++++++++++++++----------------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/dwz.c b/dwz.c
index 1be4f2a..bd40e90 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16437,6 +16437,26 @@ decode_child_exit_status (int state, struct file_result *res)
return ret;
}
+/* Wait on child exit with PID, update PIDS and RES. */
+static int
+wait_child_exit (pid_t pid, pid_t *pids, int nr_pids,
+ struct file_result *res)
+{
+ int state;
+ pid_t got_pid = waitpid (pid, &state, 0);
+
+ int i;
+ for (i = 0; i < nr_pids; ++i)
+ if (pids[i] == got_pid)
+ {
+ pids[i] = 0;
+ break;
+ }
+ assert (i < nr_pids);
+
+ return decode_child_exit_status (state, res);
+}
+
/* Dwarf-compress FILES. If HARDLINK, detect if some files are hardlinks and
if so, dwarf-compress just one, and relink the others. */
static int
@@ -16487,21 +16507,10 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
if (nr_forks == max_forks)
{
- int state;
- pid_t got_pid = waitpid (-1, &state, 0);
- int thisret
- = decode_child_exit_status (state, res);
+ int thisret = wait_child_exit (-1, pids, i, res);
if (thisret == 1)
ret = 1;
nr_forks--;
- int j;
- for (j = 0; j < i; ++j)
- if (pids[j] == got_pid)
- {
- pids[j] = 0;
- break;
- }
- assert (j < i);
}
pid_t fork_res = fork ();
@@ -16527,10 +16536,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
continue;
if (pids[i] == 0)
continue;
- int state;
- pid_t got_pid = waitpid (pids[i], &state, 0);
- assert (got_pid == pids[i]);
- thisret = decode_child_exit_status (state, res);
+ thisret = wait_child_exit (pids[i], &pids[i], 1, res);
if (thisret == 1)
ret = 1;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-03-27 12:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27 12:56 [committed] Factor out wait_child_exit Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).