[05/10] send-pack.c: remove #ifdef NO_PTHREADS
diff mbox series

Message ID 20181027071003.1347-6-pclouds@gmail.com
State New
Headers show
Series
  • Reduce #ifdef NO_PTHREADS
Related show

Commit Message

Duy Nguyen Oct. 27, 2018, 7:09 a.m. UTC
While at there correct "#include cache.h" position. It must be one of
the first includes.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 send-pack.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jeff King Oct. 27, 2018, 7:39 a.m. UTC | #1
On Sat, Oct 27, 2018 at 09:09:58AM +0200, Nguyễn Thái Ngọc Duy wrote:

> While at there correct "#include cache.h" position. It must be one of
> the first includes.
> [...]
> @@ -1,4 +1,5 @@
>  #include "builtin.h"
> +#include "cache.h"

I think it's actually fine as it is. The rule is not about cache.h in
particular, but that the first include must be one of the special ones.
And builtin.h is such a special one. After that, there are no ordering
rules.

> @@ -203,9 +204,8 @@ static int receive_status(int in, struct ref *refs)
>  static int sideband_demux(int in, int out, void *data)
>  {
>  	int *fd = data, ret;
> -#ifdef NO_PTHREADS
> -	close(fd[1]);
> -#endif
> +	if (!HAVE_THREADS)
> +		close(fd[1]);
>  	ret = recv_sideband("send-pack", fd[0], out);
>  	close(out);
>  	return ret;

This one is a very interesting case. Your conversion here isn't wrong,
but what we actually want to know is: is "struct async" implemented as a
separate process or not.

And "struct async" will continue to switch on NO_PTHREADS, as it can
never use these dummy bits. I can't think of a way that HAVE_THREADS
would ever diverge from how "struct async" works, but my gut feeling is
that we probably ought to have a separate variable for the async code to
tell how it works. Even if it ends up being the same as HAVE_THREADS,
it helps untangle the two cases.

-Peff

Patch
diff mbox series

diff --git a/send-pack.c b/send-pack.c
index e920ca57df..fa7dc44b36 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,4 +1,5 @@ 
 #include "builtin.h"
+#include "cache.h"
 #include "config.h"
 #include "commit.h"
 #include "refs.h"
@@ -14,7 +15,7 @@ 
 #include "version.h"
 #include "sha1-array.h"
 #include "gpg-interface.h"
-#include "cache.h"
+#include "thread-utils.h"
 
 int option_parse_push_signed(const struct option *opt,
 			     const char *arg, int unset)
@@ -203,9 +204,8 @@  static int receive_status(int in, struct ref *refs)
 static int sideband_demux(int in, int out, void *data)
 {
 	int *fd = data, ret;
-#ifdef NO_PTHREADS
-	close(fd[1]);
-#endif
+	if (!HAVE_THREADS)
+		close(fd[1]);
 	ret = recv_sideband("send-pack", fd[0], out);
 	close(out);
 	return ret;