public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Factor out wait_children_exit
Date: Sat, 27 Mar 2021 13:57:08 +0100	[thread overview]
Message-ID: <20210327125707.GA18336@delia> (raw)

Hi,

Factor new function wait_children_exit out of dwz_files_1.

Committed to trunk.

Thanks,
- Tom

Factor out wait_children_exit

2021-03-27  Tom de Vries  <tdevries@suse.de>

	* dwz.c (wait_children_exit): New function, factored out of ...
	(dwz_files_1): ... here.

---
 dwz.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/dwz.c b/dwz.c
index 3e7eb24..f20a47d 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16457,6 +16457,27 @@ wait_child_exit (pid_t pid, pid_t *pids, int nr_pids,
   return decode_child_exit_status (state, res);
 }
 
+/* Wait on exit of chilren in PIDS, update RESA.  */
+static int
+wait_children_exit (pid_t *pids, int nr_files, struct file_result *resa)
+{
+  int ret = 0;
+
+  int i;
+  for (i = 0; i < nr_files; i++)
+    {
+      int thisret;
+      struct file_result *res = &resa[i];
+      if (pids[i] == 0)
+	continue;
+      thisret = wait_child_exit (pids[i], &pids[i], 1, res);
+      if (thisret == 1)
+	ret = 1;
+    }
+
+  return ret;
+}
+
 /* Dwarf-compress FILES.  If HARDLINK, detect if some files are hardlinks and
    if so, dwarf-compress just one, and relink the others.  */
 static int
@@ -16492,10 +16513,10 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
   if (hardlink)
     hardlink = detect_hardlinks (nr_files, files, resa);
 
-  int nr_forks = 0;
   if (max_forks > 1 && multifile == NULL)
     {
       pid_t pids[nr_files];
+      int nr_forks = 0;
       for (i = 0; i < nr_files; i++)
 	pids[i] = 0;
       for (i = 0; i < nr_files; i++)
@@ -16528,13 +16549,9 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	      nr_forks++;
 	    }
 	}
-      for (i = 0; i < nr_files; i++)
+      if (nr_forks > 0)
 	{
-	  int thisret;
-	  struct file_result *res = &resa[i];
-	  if (pids[i] == 0)
-	    continue;
-	  thisret = wait_child_exit (pids[i], &pids[i], 1, res);
+	  int thisret = wait_children_exit (pids, nr_files, resa);
 	  if (thisret == 1)
 	    ret = 1;
 	}

                 reply	other threads:[~2021-03-27 12:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210327125707.GA18336@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).