]> git.ipfire.org Git - thirdparty/git.git/commit - run-command.c
run-command: provide in_async query function
authorJeff King <peff@peff.net>
Tue, 1 Sep 2015 20:22:43 +0000 (16:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Sep 2015 22:11:53 +0000 (15:11 -0700)
commit661a8cf408e83e4901bf09e2a48e9306622442dd
treef9bb2bd593d27765d0c23fe236ede6342e052f86
parent323598387d900263c4980b43b8a96c43cdd7b6c7
run-command: provide in_async query function

It's not easy for arbitrary code to find out whether it is
running in an async process or not. A top-level function
which is fed to start_async() can know (you just pass down
an argument saying "you are async"). But that function may
call other global functions, and we would not want to have
to pass the information all the way through the call stack.

Nor can we simply set a global variable, as those may be
shared between async threads and the main thread (if the
platform supports pthreads). We need pthread tricks _or_ a
global variable, depending on how start_async is
implemented.

The callers don't have enough information to do this right,
so let's provide a simple query function that does.
Fortunately we can reuse the existing infrastructure to make
the pthread case simple (and even simplify die_async() by
using our new function).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
run-command.h