git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Beller <sbeller@google.com>
To: sbeller@google.com
Cc: tboegi@web.de, j6t@kdbg.org, gitster@pobox.com,
	git@vger.kernel.org, johannes.schindelin@gmx.de
Subject: [PATCH 2/2] run-parallel: Run sequential if nonblocking I/O is unavailable
Date: Wed,  4 Nov 2015 14:43:49 -0800	[thread overview]
Message-ID: <1446677029-10745-3-git-send-email-sbeller@google.com> (raw)
In-Reply-To: <1446677029-10745-1-git-send-email-sbeller@google.com>

Windows doesn't have O_NONBLOCK nor F_GETFL defined, so we need cannot run
in parallel there. Instead the children will output directly to our stderr
and we run one child at a time.

Bonus: We are setting process.err = -1; which we previously expected the
get_next_task callback to do. It is easy to forget that part in the callback
leading to hard to debug errors.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/run-command.c b/run-command.c
index 86fbe50..19de253 100644
--- a/run-command.c
+++ b/run-command.c
@@ -958,6 +958,10 @@ static struct parallel_processes *pp_init(int n,
 	if (n < 1)
 		n = online_cpus();
 
+#if !(defined (O_NONBLOCK) && defined (F_GETFL))
+	n = 1;
+#endif
+
 	pp->max_processes = n;
 	pp->data = data;
 	if (!get_next_task)
@@ -1006,6 +1010,7 @@ static void pp_cleanup(struct parallel_processes *pp)
 	sigchain_pop_common();
 }
 
+#if defined (O_NONBLOCK) && defined (F_GETFL)
 static void set_nonblocking_or_die(int fd)
 {
 	int flags = fcntl(fd, F_GETFL);
@@ -1014,6 +1019,7 @@ static void set_nonblocking_or_die(int fd)
 	else if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
 		die("Could not set file status flags");
 }
+#endif
 
 /* returns
  *  0 if a new task was started.
@@ -1031,6 +1037,12 @@ static int pp_start_one(struct parallel_processes *pp)
 	if (i == pp->max_processes)
 		die("BUG: bookkeeping is hard");
 
+#if defined (O_NONBLOCK) && defined (F_GETFL)
+	pp->children[i].process.err = -1;
+#else
+	pp->children[i].process.err = 2;
+#endif
+
 	if (!pp->get_next_task(&pp->children[i].data,
 			       &pp->children[i].process,
 			       &pp->children[i].err,
@@ -1049,8 +1061,9 @@ static int pp_start_one(struct parallel_processes *pp)
 		strbuf_reset(&pp->children[i].err);
 		return code ? -1 : 1;
 	}
-
+#if defined (O_NONBLOCK) && defined (F_GETFL)
 	set_nonblocking_or_die(pp->children[i].process.err);
+#endif
 
 	pp->nr_processes++;
 	pp->children[i].in_use = 1;
-- 
2.6.1.247.ge8f2a41.dirty

      parent reply	other threads:[~2015-11-04 22:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02  2:58 git.git as of tonight Junio C Hamano
2015-11-02 21:15 ` Johannes Sixt
2015-11-02 22:16   ` Junio C Hamano
2015-11-02 23:06   ` Stefan Beller
2015-11-03  6:34     ` Johannes Sixt
2015-11-03 17:05       ` Junio C Hamano
2015-11-03 18:18         ` Stefan Beller
2015-11-03 21:03           ` Johannes Sixt
2015-11-03 23:00             ` Stefan Beller
2015-11-04 19:59               ` O_NONBLOCK under Windows (was: git.git as of tonight) Torsten Bögershausen
2015-11-04 20:07                 ` Stefan Beller
2015-11-04 22:43                 ` [PATCH 0/2] Missing " Stefan Beller
2015-11-04 22:43                   ` [PATCH 1/2] run-parallel: rename set_nonblocking to set_nonblocking_or_die Stefan Beller
2015-11-05  6:07                     ` Torsten Bögershausen
2015-11-05  6:14                       ` Junio C Hamano
2015-11-05  6:19                         ` Junio C Hamano
2015-11-05  6:58                           ` Jeff King
2015-11-04 22:43                   ` Stefan Beller [this message]

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=1446677029-10745-3-git-send-email-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=tboegi@web.de \
    /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 NNTP newsgroup(s).