From: Jeff King <peff@peff.net>
To: Rasmus Villemoes <rv@rasmusvillemoes.dk>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/3] grep: move grep_source_init outside critical section
Date: Thu, 15 Feb 2018 17:17:13 -0500 [thread overview]
Message-ID: <20180215221713.GB23970@sigill.intra.peff.net> (raw)
In-Reply-To: <20180215215615.21208-2-rv@rasmusvillemoes.dk>
On Thu, Feb 15, 2018 at 10:56:13PM +0100, Rasmus Villemoes wrote:
> 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:
> + 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
next prev parent reply other threads:[~2018-02-15 22:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 21:56 [PATCH 0/3] a few grep patches Rasmus Villemoes
2018-02-15 21:56 ` [PATCH 1/3] grep: move grep_source_init outside critical section Rasmus Villemoes
2018-02-15 22:17 ` Jeff King [this message]
2018-02-16 19:24 ` Junio C Hamano
2018-02-15 21:56 ` [PATCH 2/3] grep: simplify grep_oid and grep_file Rasmus Villemoes
2018-02-15 21:56 ` [PATCH 3/3] grep: avoid one strdup() per file Rasmus Villemoes
2018-02-15 22:18 ` Jeff King
2018-02-15 22:02 ` [PATCH 0/3] a few grep patches Brandon Williams
2018-02-23 14:47 ` [PATCH v2 0/2] two small " Rasmus Villemoes
2018-02-23 14:47 ` [PATCH v2 1/2] grep: move grep_source_init outside critical section Rasmus Villemoes
2018-02-23 14:47 ` [PATCH v2 2/2] grep: simplify grep_oid and grep_file Rasmus Villemoes
2018-02-23 18:01 ` [PATCH v2 0/2] two small grep patches Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180215221713.GB23970@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=rv@rasmusvillemoes.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).