git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 03/14] send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.c

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Nov 3, 2018, 08:48 UTC
Message-ID
<20181103084850.9584-4-pclouds@gmail.com>
In-Reply-To
<20181103084850.9584-1-pclouds@gmail.com>

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>
---
 run-command.c | 9 +++++++++
 run-command.h | 1 +
 send-pack.c   | 5 ++---
 3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/run-command.c b/run-command.c
index 84b883c213..3c3b8814df 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1246,6 +1246,15 @@ int finish_async(struct async *async)
 #endif
 }
 
+int async_with_fork(void)
+{
+#ifdef NO_PTHREADS
+	return 1;
+#else
+	return 0;
+#endif
+}
+
 const char *find_hook(const char *name)
 {
 	static struct strbuf path = STRBUF_INIT;
diff --git a/run-command.h b/run-command.h
index 9b7f38202c..68f5369fc2 100644
--- a/run-command.h
+++ b/run-command.h
@@ -141,6 +141,7 @@ struct async {
 int start_async(struct async *async);
 int finish_async(struct async *async);
 int in_async(void);
+int async_with_fork(void);
 void check_pipe(int err);
 
 /**
diff --git a/send-pack.c b/send-pack.c
index e920ca57df..f692686770 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -203,9 +203,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 (async_with_fork())
+		close(fd[1]);
 	ret = recv_sideband("send-pack", fd[0], out);
 	close(out);
 	return ret;
-- 
2.19.1.1005.gac84295441
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 54 of 66 in “Reduce #ifdef NO_PTHREADS”
  1. 00/10 Reduce #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  2. 01/10 thread-utils: macros to unconditionally compile pthreads APINguyễn Thái Ngọc Duy, Oct 27, 2018
  3. Jeff KingOct 27, 2018
  4. Duy NguyenOct 27, 2018
  5. Jeff KingOct 27, 2018
  6. Duy NguyenOct 27, 2018
  7. 03/10 name-hash.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  8. 04/10 attr.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  9. 05/10 send-pack.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  10. Jeff KingOct 27, 2018
  11. 06/10 grep: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  12. Jeff KingOct 27, 2018
  13. Junio C HamanoOct 29, 2018
  14. Jeff KingOct 29, 2018
  15. Duy NguyenOct 29, 2018
  16. Jeff KingOct 29, 2018
  17. Junio C HamanoOct 30, 2018
  18. 02/10 index-pack: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  19. Jeff KingOct 27, 2018
  20. 07/10 preload-index.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  21. Ben PeartOct 29, 2018
  22. 08/10 pack-objects: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  23. 09/10 read-cache.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  24. Ben PeartOct 29, 2018
  25. Duy NguyenOct 29, 2018
  26. Ben PeartOct 29, 2018
  27. Junio C HamanoOct 30, 2018
  28. 10/10 Clean up pthread_create() error handlingNguyễn Thái Ngọc Duy, Oct 27, 2018
  29. Jeff KingOct 27, 2018
  30. Jeff KingOct 27, 2018
  31. Duy NguyenOct 27, 2018
  32. 00/10 Reduce #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  33. 01/10 thread-utils: macros to unconditionally compile pthreads APINguyễn Thái Ngọc Duy, Oct 27, 2018
  34. 02/10 index-pack: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  35. 04/10 attr.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  36. 03/10 name-hash.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  37. 05/10 grep: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  38. 06/10 preload-index.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  39. Ben PeartOct 29, 2018
  40. Duy NguyenOct 29, 2018
  41. Ben PeartOct 29, 2018
  42. Jeff KingOct 29, 2018
  43. 07/10 pack-objects: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  44. 08/10 read-cache.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 27, 2018
  45. Jeff KingOct 29, 2018
  46. Ben PeartOct 29, 2018
  47. Ben PeartOct 29, 2018
  48. 09/10 Clean up pthread_create() error handlingNguyễn Thái Ngọc Duy, Oct 27, 2018
  49. 10/10 read-cache.c: initialize copy_len to shut up gcc 8Nguyễn Thái Ngọc Duy, Oct 27, 2018
  50. Jeff KingOct 29, 2018
  51. 00/14 Reduce #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  52. 01/14 thread-utils: macros to unconditionally compile pthreads APINguyễn Thái Ngọc Duy, Nov 3, 2018
  53. 02/14 run-command.h: include thread-utils.h instead of pthread.hNguyễn Thái Ngọc Duy, Nov 3, 2018
  54. 03/14 send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.cNguyễn Thái Ngọc Duy, Nov 3, 2018
  55. 04/14 index-pack: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  56. 05/14 name-hash.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  57. 06/14 attr.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  58. 07/14 grep: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  59. 09/14 preload-index.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  60. 08/14 grep: clean up num_threads handlingNguyễn Thái Ngọc Duy, Nov 3, 2018
  61. 10/14 pack-objects: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  62. 11/14 read-cache.c: remove #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  63. 12/14 read-cache.c: reduce branching based on HAVE_THREADSNguyễn Thái Ngọc Duy, Nov 3, 2018
  64. 13/14 read-cache.c: initialize copy_len to shut up gcc 8Nguyễn Thái Ngọc Duy, Nov 3, 2018
  65. 14/14 Clean up pthread_create() error handlingNguyễn Thái Ngọc Duy, Nov 3, 2018
  66. Junio C HamanoNov 6, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.