send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.c
On systems that do not support multithread, start_async() is implemented with fork(). This implementation details unfortunately leak out at least in send-pack.c [1]. To keep the code base clean of NO_PTHREADS, move the this #ifdef back to run-command.c. The new wrapper function async_with_fork() at least helps suggest that this special "close()" is related to async in fork mode. [1] 09c9957cf7 (send-pack: avoid deadlock when pack-object dies early - 2011-04-25) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 3, 2018 at 09:48 UTC
c0e40a2d66e3b95d13bbc2e6e58d7b5c029d94ab
3 files changed
+12
-3
run-command.c
+9
@@ -1246,6 +1246,15 @@ int finish_async(struct async *async)
1246
#endif
1247
}
1248
1249
+int async_with_fork(void)
1250
+{
1251
+#ifdef NO_PTHREADS
1252
+ return 1;
1253
+#else
1254
+ return 0;
1255
+#endif
1256
+}
1257
+
1258
const char *find_hook(const char *name)
1259
{
1260
static struct strbuf path = STRBUF_INIT;
run-command.h
+1
@@ -141,6 +141,7 @@ struct async {
141
int start_async(struct async *async);
142
int finish_async(struct async *async);
143
int in_async(void);
144
+int async_with_fork(void);
145
void check_pipe(int err);
146
147
/**
send-pack.c
+2
-3
@@ -203,9 +203,8 @@ static int receive_status(int in, struct ref *refs)
203
static int sideband_demux(int in, int out, void *data)
204
{
205
int *fd = data, ret;
206
-#ifdef NO_PTHREADS
207
- close(fd[1]);
208
-#endif
206
+ if (async_with_fork())
207
+ close(fd[1]);
208
ret = recv_sideband("send-pack", fd[0], out);
209
close(out);
210
return ret;