public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Introduce struct pipe
@ 2021-04-13 12:32 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-04-13 12:32 UTC (permalink / raw)
  To: dwz, jakub, mark

Hi,

Introduce struct pipe that names the read and write fd of a pipe.

Committed to trunk.

Thanks,
- Tom

Introduce struct pipe

2021-04-13  Tom de Vries  <tdevries@suse.de>

	* dwz.c (struct pipe): New type.
	(pipes): Change variable type to struct type *.
	(get_token, pass_token, dwz_files_1): Update.

---
 dwz.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/dwz.c b/dwz.c
index 879fae6..a3b289f 100644
--- a/dwz.c
+++ b/dwz.c
@@ -15147,18 +15147,23 @@ write_multifile_1 (DSO *dso, struct file_result *res)
   return ret;
 }
 
+struct pipe
+{
+  int readfd;
+  int writefd;
+};
+
 static bool write_multifile_parallel_p;
 static int child_id;
-static int *pipes;
+static struct pipe *pipes;
 
 /* Get token.  */
 static void
 get_token (void)
 {
   int n = child_id;
-  int *base = &pipes[n * 2];
-  int readfd = base[0];
-  int writefd = base[1];
+  int readfd = pipes[n].readfd;
+  int writefd = pipes[n].writefd;
   close (writefd);
   char buf;
   read (readfd, &buf, 1);
@@ -15169,9 +15174,8 @@ get_token (void)
 static void
 pass_token (int n)
 {
-  int *base = &pipes[n * 2];
-  int readfd = base[0];
-  int writefd = base[1];
+  int readfd = pipes[n].readfd;
+  int writefd = pipes[n].writefd;
   close (readfd);
   char buf = '\0';
   write (writefd, &buf, 1);
@@ -16536,8 +16540,8 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	     int fds[2];
 	     if (pipe (fds) != 0)
 	       error (1, ENOMEM, "failed to initialize pipe");
-	     pipes[i * 2] = fds[0];
-	     pipes[i * 2 + 1] = fds[1];
+	     pipes[i].readfd = fds[0];
+	     pipes[i].writefd = fds[1];
 	   }
        }
      else

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

only message in thread, other threads:[~2021-04-13 12:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 12:32 [committed] Introduce struct pipe 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).