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

Re: [PATCH 1/2] run-command: provide in_async query function

From
Jeff King <peff@peff.net>
Date
Sep 1, 2015, 20:26 UTC
Message-ID
<20150901202609.GA8063@sigill.intra.peff.net>
In-Reply-To
<20150901202243.GA6931@sigill.intra.peff.net>
On Tue, Sep 01, 2015 at 04:22:43PM -0400, Jeff King wrote:
> diff --git a/run-command.c b/run-command.c
> index 3277cf7..c8029f2 100644
> --- a/run-command.c
> +++ b/run-command.c

This diff is a little funny to read because the interesting context is far away, and it is not immediately obvious why we are defining the function twice. This:

Show 21 quoted lines
> @@ -595,7 +595,7 @@ static NORETURN void die_async(const char *err, va_list params)
>  {
>  	vreportf("fatal: ", err, params);
>  
> -	if (!pthread_equal(main_thread, pthread_self())) {
> +	if (in_async()) {
>  		struct async *async = pthread_getspecific(async_key);
>  		if (async->proc_in >= 0)
>  			close(async->proc_in);
> @@ -614,6 +614,13 @@ static int async_die_is_recursing(void)
>  	return ret != NULL;
>  }
>  
> +int in_async(void)
> +{
> +	if (!main_thread_set)
> +		return 0; /* no asyncs started yet */
> +	return !pthread_equal(main_thread, pthread_self());
> +}
> +
>  #else
is all inside #ifndef NO_PTHREADS, and this:
Show 11 quoted lines
> @@ -653,6 +660,12 @@ int git_atexit(void (*handler)(void))
>  }
>  #define atexit git_atexit
>  
> +static int process_is_async;
> +int in_async(void)
> +{
> +	return process_is_async;
> +}
> +
>  #endif
is the "#else" case where we fork.
-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 12 in “clarify sideband muxing in GIT_TRACE_PACKET”
  1. 0/2 clarify sideband muxing in GIT_TRACE_PACKETJeff King, Sep 1, 2015
  2. 1/2 run-command: provide in_async query functionJeff King, Sep 1, 2015
  3. Jeff KingSep 1, 2015
  4. Junio C HamanoSep 1, 2015
  5. Jeff KingSep 1, 2015
  6. 2/2 pkt-line: show packets in async processes as "sideband"Jeff King, Sep 1, 2015
  7. Junio C HamanoSep 1, 2015
  8. Jeff KingSep 1, 2015
  9. Stefan BellerSep 1, 2015
  10. Jeff KingSep 1, 2015
  11. Stefan BellerSep 1, 2015
  12. Jeff KingSep 1, 2015

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.