Thread (10 messages) 10 messages, 2 authors, 2017-05-12

[PATCH 2/7] grep: skip pthreads overhead when using one thread

flat view
STALE3436d

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2017-05-11 17:02:24
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v1 of 5 in this series.

Revisions (5)
  1. v1 current
  2. v2 [diff vs current]
  3. v2 [diff vs current]
  4. v3 [diff vs current]
  5. v4 [diff vs current]
Skip the administrative overhead of using pthreads when only using one
thread. Instead take the non-threaded path which would be taken under
NO_PTHREADS.

The threading support was initially added in commit
5b594f457a ("Threaded grep", 2010-01-25) with a hardcoded compile-time
number of 8 threads. Later the number of threads was made configurable
in commit 89f09dd34e ("grep: add --threads=<num> option and
grep.threads configuration", 2015-12-15).

That change did not add any special handling for --threads=1. Now we
take a slightly faster path by skipping thread handling entirely when
1 thread is requested.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 builtin/grep.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/builtin/grep.c b/builtin/grep.c
index 7baa4778b7..9c0d1ecc12 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1240,6 +1240,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		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"));
-- 
2.11.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help