]> git.ipfire.org Git - thirdparty/git.git/commit - grep.c
grep: make locking flag global
authorJeff King <peff@peff.net>
Thu, 2 Feb 2012 08:18:29 +0000 (03:18 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Feb 2012 18:36:07 +0000 (10:36 -0800)
commit78db6ea9dc1a872f9d07a36fe7aec700a5c963b9
tree9dd1308cd344c12239a17a698355c836e49c7200
parent828ea97de486c1693d6e4f2c7347acb50235a85d
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>
builtin/grep.c
grep.c
grep.h