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

[PATCH v2 05/10] grep: remove #ifdef NO_PTHREADS

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 27, 2018, 17:30 UTC
Message-ID
<20181027173008.18852-6-pclouds@gmail.com>
In-Reply-To
<20181027173008.18852-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/grep.c | 59 +++++++++++++++++++-------------------------------
 grep.c         |  6 -----
 grep.h         |  6 -----
 3 files changed, 22 insertions(+), 49 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index d8508ddf79..6dd15dbaa2 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -34,7 +34,6 @@ static int recurse_submodules;
 #define GREP_NUM_THREADS_DEFAULT 8
 static int num_threads;
 
-#ifndef NO_PTHREADS
 static pthread_t *threads;
 
 /* We use one producer thread and THREADS consumer
@@ -234,6 +233,9 @@ static int wait_all(void)
 	int hit = 0;
 	int i;
 
+	if (!HAVE_THREADS)
+		return 0;
+
 	grep_lock();
 	all_work_added = 1;
 
@@ -265,13 +267,6 @@ static int wait_all(void)
 
 	return hit;
 }
-#else /* !NO_PTHREADS */
-
-static int wait_all(void)
-{
-	return 0;
-}
-#endif
 
 static int grep_cmd_config(const char *var, const char *value, void *cb)
 {
@@ -284,8 +279,7 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
 		if (num_threads < 0)
 			die(_("invalid number of threads specified (%d) for %s"),
 			    num_threads, var);
-#ifdef NO_PTHREADS
-		else if (num_threads && num_threads != 1) {
+		else if (!HAVE_THREADS && num_threads && num_threads != 1) {
 			/*
 			 * TRANSLATORS: %s is the configuration
 			 * variable for tweaking threads, currently
@@ -294,7 +288,6 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
 			warning(_("no threads support, ignoring %s"), var);
 			num_threads = 0;
 		}
-#endif
 	}
 
 	if (!strcmp(var, "submodule.recurse"))
@@ -330,17 +323,14 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
 	grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
 	strbuf_release(&pathbuf);
 
-#ifndef NO_PTHREADS
-	if (num_threads) {
+	if (HAVE_THREADS && num_threads) {
 		/*
 		 * add_work() copies gs and thus assumes ownership of
 		 * its fields, so do not call grep_source_clear()
 		 */
 		add_work(opt, &gs);
 		return 0;
-	} else
-#endif
-	{
+	} else {
 		int hit;
 
 		hit = grep_source(opt, &gs);
@@ -363,17 +353,14 @@ static int grep_file(struct grep_opt *opt, const char *filename)
 	grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
 	strbuf_release(&buf);
 
-#ifndef NO_PTHREADS
-	if (num_threads) {
+	if (HAVE_THREADS && num_threads) {
 		/*
 		 * add_work() copies gs and thus assumes ownership of
 		 * its fields, so do not call grep_source_clear()
 		 */
 		add_work(opt, &gs);
 		return 0;
-	} else
-#endif
-	{
+	} else {
 		int hit;
 
 		hit = grep_source(opt, &gs);
@@ -1038,20 +1025,20 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	pathspec.recursive = 1;
 	pathspec.recurse_submodules = !!recurse_submodules;
 
-#ifndef NO_PTHREADS
-	if (list.nr || cached || show_in_pager)
-		num_threads = 0;
-	else if (num_threads == 0)
-		num_threads = GREP_NUM_THREADS_DEFAULT;
-	else if (num_threads < 0)
-		die(_("invalid number of threads specified (%d)"), num_threads);
-	if (num_threads == 1)
+	if (HAVE_THREADS) {
+		if (list.nr || cached || show_in_pager)
+			num_threads = 0;
+		else if (num_threads == 0)
+			num_threads = GREP_NUM_THREADS_DEFAULT;
+		else if (num_threads < 0)
+			die(_("invalid number of threads specified (%d)"), num_threads);
+		if (num_threads == 1)
+			num_threads = 0;
+	} else {
+		if (num_threads)
+			warning(_("no threads support, ignoring --threads"));
 		num_threads = 0;
-#else
-	if (num_threads)
-		warning(_("no threads support, ignoring --threads"));
-	num_threads = 0;
-#endif
+	}
 
 	if (!num_threads)
 		/*
@@ -1062,15 +1049,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		 */
 		compile_grep_patterns(&opt);
 
-#ifndef NO_PTHREADS
-	if (num_threads) {
+	if (HAVE_THREADS && num_threads) {
 		if (!(opt.name_only || opt.unmatch_name_only || opt.count)
 		    && (opt.pre_context || opt.post_context ||
 			opt.file_break || opt.funcbody))
 			skip_first_line = 1;
 		start_threads(&opt);
 	}
-#endif
 
 	if (show_in_pager && (cached || list.nr))
 		die(_("--open-files-in-pager only works on the worktree"));
diff --git a/grep.c b/grep.c
index f6bd89e40b..4db1510d16 100644
--- a/grep.c
+++ b/grep.c
@@ -1513,7 +1513,6 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
 	}
 }
 
-#ifndef NO_PTHREADS
 int grep_use_locks;
 
 /*
@@ -1539,11 +1538,6 @@ static inline void grep_attr_unlock(void)
  */
 pthread_mutex_t grep_read_mutex;
 
-#else
-#define grep_attr_lock()
-#define grep_attr_unlock()
-#endif
-
 static int match_funcname(struct grep_opt *opt, struct grep_source *gs, char *bol, char *eol)
 {
 	xdemitconf_t *xecfg = opt->priv;
diff --git a/grep.h b/grep.h
index 1a57d12b90..fb04893721 100644
--- a/grep.h
+++ b/grep.h
@@ -229,7 +229,6 @@ int grep_source(struct grep_opt *opt, struct grep_source *gs);
 extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
 extern int grep_threads_ok(const struct grep_opt *opt);
 
-#ifndef NO_PTHREADS
 /*
  * Mutex used around access to the attributes machinery if
  * opt->use_threads.  Must be initialized/destroyed by callers!
@@ -250,9 +249,4 @@ static inline void grep_read_unlock(void)
 		pthread_mutex_unlock(&grep_read_mutex);
 }
 
-#else
-#define grep_read_lock()
-#define grep_read_unlock()
-#endif
-
 #endif
-- 
2.19.1.647.g708186aaf9
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 37 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.