summaryrefslogtreecommitdiff
path: root/grep.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-02-02 03:18:29 -0500
committerJunio C Hamano <gitster@pobox.com>2012-02-02 10:36:07 -0800
commit78db6ea9dc1a872f9d07a36fe7aec700a5c963b9 (patch)
tree9dd1308cd344c12239a17a698355c836e49c7200 /grep.h
parent828ea97de486c1693d6e4f2c7347acb50235a85d (diff)
downloadgit-78db6ea9dc1a872f9d07a36fe7aec700a5c963b9.tar.gz
grep: make locking flag global
The low-level grep code traditionally didn't care about threading, as it doesn't do any threading itself and didn't call out to other non-thread-safe code. That changed with 0579f91 (grep: enable threading with -p and -W using lazy attribute lookup, 2011-12-12), which pushed the lookup of funcname attributes (which is not thread-safe) into the low-level grep code. As a result, the low-level code learned about a new global "grep_attr_mutex" to serialize access to the attribute code. A multi-threaded caller (e.g., builtin/grep.c) is expected to initialize the mutex and set "use_threads" in the grep_opt structure. The low-level code only uses the lock if use_threads is set. However, putting the use_threads flag into the grep_opt struct is not the most logical place. Whether threading is in use is not something that matters for each call to grep_buffer, but is instead global to the whole program (i.e., if any thread is doing multi-threaded grep, every other thread, even if it thinks it is doing its own single-threaded grep, would need to use the locking). In practice, this distinction isn't a problem for us, because the only user of multi-threaded grep is "git-grep", which does nothing except call grep. This patch turns the opt->use_threads flag into a global flag. More important than the nit-picking semantic argument above is that this means that the locking functions don't need to actually have access to a grep_opt to know whether to lock. Which in turn can make adding new locks simpler, as we don't need to pass around a grep_opt. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.h')
-rw-r--r--grep.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/grep.h b/grep.h
index fb205f3542..3653bb333c 100644
--- a/grep.h
+++ b/grep.h
@@ -116,7 +116,6 @@ struct grep_opt {
int show_hunk_mark;
int file_break;
int heading;
- int use_threads;
void *priv;
void (*output)(struct grep_opt *opt, const void *data, size_t size);
@@ -138,6 +137,7 @@ extern int grep_threads_ok(const struct grep_opt *opt);
* Mutex used around access to the attributes machinery if
* opt->use_threads. Must be initialized/destroyed by callers!
*/
+extern int grep_use_locks;
extern pthread_mutex_t grep_attr_mutex;
#endif