grep: move grep_source_init outside critical section
commite2e05d619a71ae2c06ebd3c661260bf4b5039a93
authorRasmus Villemoes <rv@rasmusvillemoes.dk>
Fri, 23 Feb 2018 14:47:56 +0000 (23 15:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 23 Feb 2018 20:23:26 +0000 (23 12:23 -0800)
treee35c04b70ddfeddb057365ecd899cb16a2bd5cfb
parentffa952497288d29d94b16675c6789ef83850def3
grep: move grep_source_init outside critical section

grep_source_init typically does three strdup()s, and in the threaded
case, the call from add_work() happens while holding grep_mutex.

We can thus reduce the time we hold grep_mutex by moving the
grep_source_init() call out of add_work(), and simply have add_work()
copy the initialized structure to the available slot in the todo
array.

This also simplifies the prototype of add_work(), since it no longer
needs to duplicate all the parameters of grep_source_init(). In the
callers of add_work(), we get to reduce the amount of code duplicated in
the threaded and non-threaded cases slightly (avoiding repeating the
long "GREP_SOURCE_OID, pathbuf.buf, path, oid" argument list); a
subsequent cleanup patch will make that even more so.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c