public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Add ret to struct file_result
@ 2021-03-29  6:36 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-29  6:36 UTC (permalink / raw)
  To: dwz, jakub, mark

Hi,

Further simplify the serial/parallel code in dwz_files_1 by factoring out the
return status handling.  Add a ret field to struct file_result to store the
per-file return status.

Committed to trunk.

Thanks,
- Tom

Add ret to struct file_result

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

	* dwz.c (struct file_result): Add ret field.
	(wait_child_exit): Return void.  Set ret.
	(wait_children_exit): Return void.  Update call to wait_child_exit.
	(dwz_files_1): Move return status handling out of serial/parallel code.

---
 dwz.c | 68 ++++++++++++++++++++++++++++++++-----------------------------------
 1 file changed, 32 insertions(+), 36 deletions(-)

diff --git a/dwz.c b/dwz.c
index 377e1be..de600c1 100644
--- a/dwz.c
+++ b/dwz.c
@@ -15049,6 +15049,7 @@ struct file_result
       0: Processed, changed.
       1: Processed, unchanged.  */
   int res;
+  int ret;
   size_t hardlink_to;
   unsigned int die_count;
   bool skip_multifile;
@@ -16444,7 +16445,7 @@ decode_child_exit_status (int state, struct file_result *res)
 }
 
 /* Wait on child exit with PID, update PIDS and RES.  */
-static int
+static void
 wait_child_exit (pid_t pid, pid_t *pids, int nr_pids,
 		 struct file_result *resa)
 {
@@ -16460,28 +16461,21 @@ wait_child_exit (pid_t pid, pid_t *pids, int nr_pids,
       }
   assert (i < nr_pids);
 
-  return decode_child_exit_status (state, &resa[i]);
+  resa[i].ret = decode_child_exit_status (state, &resa[i]);
 }
 
 /* Wait on exit of chilren in PIDS, update RESA.  */
-static int
+static void
 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;
+      wait_child_exit (pids[i], &pids[i], 1, res);
     }
-
-  return ret;
 }
 
 /* Dwarf-compress FILES.  If HARDLINK, detect if some files are hardlinks and
@@ -16540,13 +16534,10 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
       for (j = 0; j < workset_size; j++)
 	{
 	  int i = workset[j];
-	  int thisret;
 
 	  if (nr_forks == max_forks)
 	    {
-	      int thisret = wait_child_exit (-1, pids, i, resa);
-	      if (thisret == 1)
-		ret = 1;
+	      wait_child_exit (-1, pids, i, resa);
 	      nr_forks--;
 	    }
 
@@ -16556,7 +16547,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	    {
 	      file = files[i];
 	      struct file_result *res = &resa[i];
-	      thisret = dwz_with_low_mem (file, NULL, res);
+	      int thisret = dwz_with_low_mem (file, NULL, res);
 	      return encode_child_exit_status (thisret, res);
 	    }
 	  else
@@ -16566,30 +16557,32 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	    }
 	}
       if (nr_forks > 0)
-	{
-	  int thisret = wait_children_exit (pids, nr_files, resa);
-	  if (thisret == 1)
-	    ret = 1;
-	}
+	wait_children_exit (pids, nr_files, resa);
     }
   else
     {
       for (j = 0; j < workset_size; j++)
 	{
 	  int i = workset[j];
-	  int thisret;
 	  file = files[i];
 	  struct file_result *res = &resa[i];
 	  if (stats_p)
 	    init_stats (file);
-	  thisret = dwz_with_low_mem (file, NULL, res);
-	  if (thisret == 1)
-	    ret = 1;
-	  else if (!res->low_mem_p && !res->skip_multifile && res->res >= 0)
-	    successcount++;
+	  res->ret = dwz_with_low_mem (file, NULL, res);
 	}
     }
 
+  for (j = 0; j < workset_size; j++)
+    {
+      int i = workset[j];
+      struct file_result *res = &resa[i];
+      int thisret = res->ret;
+      if (thisret == 1)
+	ret = 1;
+      else if (!res->low_mem_p && !res->skip_multifile && res->res >= 0)
+	successcount++;
+    }
+
   if (hardlink)
     update_hardlinks (nr_files, files, resa);
 
@@ -16647,9 +16640,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 
 	  if (nr_forks == max_forks)
 	    {
-	      int thisret = wait_child_exit (-1, pids, i, resa);
-	      if (thisret == 1)
-		ret = 1;
+	      wait_child_exit (-1, pids, i, resa);
 	      nr_forks--;
 	    }
 
@@ -16670,17 +16661,14 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	    }
 	}
       if (nr_forks > 0)
-	{
-	  int thisret = wait_children_exit (pids, nr_files, resa);
-	  if (thisret == 1)
-	    ret = 1;
-	}
+	wait_children_exit (pids, nr_files, resa);
     }
   else
     {
       for (j = 0; j < workset_size; j++)
 	{
 	  int i = workset[j];
+	  struct file_result *res = &resa[i];
 	  dw_cu_ref cu;
 	  file = files[i];
 	  if (stats_p)
@@ -16688,10 +16676,18 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	  multifile_mode = MULTIFILE_MODE_FI;
 	  for (cu = alt_first_cu; cu; cu = cu->cu_next)
 	    alt_clear_dups (cu->cu_die);
-	  ret |= dwz (file, NULL, &resa[i]);
+	  res->ret = dwz (file, NULL, res);
 	}
     }
 
+  for (j = 0; j < workset_size; j++)
+    {
+      int i = workset[j];
+      struct file_result *res = &resa[i];
+      int thisret = res->ret;
+      ret |= thisret;
+    }
+
   if (hardlink)
     update_hardlinks (nr_files, files, resa);
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-29  6:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29  6:36 [committed] Add ret to struct file_result 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).