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

Re: [PATCH 1/3] grep: move grep_source_init outside critical section

From
Jeff King <peff@peff.net>
Date
Feb 15, 2018, 22:17 UTC
Message-ID
<20180215221713.GB23970@sigill.intra.peff.net>
In-Reply-To
<20180215215615.21208-2-rv@rasmusvillemoes.dk>
On Thu, Feb 15, 2018 at 10:56:13PM +0100, Rasmus Villemoes wrote:
Show 14 quoted lines
> 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
> "GREP_SOURCE_OID, pathbuf.buf, path, oid" argument list); a subsequent
> cleanup patch will make that even more so.

I think this makes sense. It does blur the memory ownership lines of the grep_source, though. Can we make that more clear with a comment here:

Show 9 quoted lines
> +	grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
> +
>  #ifndef NO_PTHREADS
>  	if (num_threads) {
> -		add_work(opt, GREP_SOURCE_OID, pathbuf.buf, path, oid);
> +		add_work(opt, &gs);
>  		strbuf_release(&pathbuf);
>  		return 0;
>  	} else
like:
  /* leak grep_source, whose fields are now owned by add_work() */

or something? We could even memset() it back to all-zeroes to avoid an accidental call to grep_source_clear(), but that's probably unnecessary if we have a comment.

-Peff
Previous: Rasmus VillemoesNext: Junio C Hamano
Message 3 of 12 in “a few grep patches”
  1. 0/3 a few grep patchesRasmus Villemoes, Feb 15, 2018
  2. 1/3 grep: move grep_source_init outside critical sectionRasmus Villemoes, Feb 15, 2018
  3. Jeff KingFeb 15, 2018
  4. Junio C HamanoFeb 16, 2018
  5. 3/3 grep: avoid one strdup() per fileRasmus Villemoes, Feb 15, 2018
  6. Jeff KingFeb 15, 2018
  7. 2/3 grep: simplify grep_oid and grep_fileRasmus Villemoes, Feb 15, 2018
  8. Brandon WilliamsFeb 15, 2018
  9. 0/2 two small grep patchesRasmus Villemoes, Feb 23, 2018
  10. 2/2 grep: simplify grep_oid and grep_fileRasmus Villemoes, Feb 23, 2018
  11. 1/2 grep: move grep_source_init outside critical sectionRasmus Villemoes, Feb 23, 2018
  12. Jeff KingFeb 23, 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.