Skip to content

Commit f6b6098

Browse files
j6tgitster
authored andcommitted
Enable threaded async procedures whenever pthreads is available
Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0ea1c89 commit f6b6098

4 files changed

Lines changed: 10 additions & 14 deletions

File tree

Documentation/technical/api-run-command.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ The function pointer in .proc has the following signature:
231231

232232

233233
There are serious restrictions on what the asynchronous function can do
234-
because this facility is implemented by a pipe to a forked process on
235-
UNIX, but by a thread in the same address space on Windows:
234+
because this facility is implemented by a thread in the same address
235+
space on most platforms (when pthreads is available), but by a pipe to
236+
a forked process otherwise:
236237

237238
. It cannot change the program's state (global variables, environment,
238239
etc.) in a way that the caller notices; in other words, .in and .out

Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,6 @@ ifeq ($(uname_S),Windows)
979979
NO_CURL = YesPlease
980980
NO_PYTHON = YesPlease
981981
BLK_SHA1 = YesPlease
982-
ASYNC_AS_THREAD = YesPlease
983982

984983
CC = compat/vcbuild/scripts/clink.pl
985984
AR = compat/vcbuild/scripts/lib.pl
@@ -1031,7 +1030,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
10311030
NO_REGEX = YesPlease
10321031
NO_PYTHON = YesPlease
10331032
BLK_SHA1 = YesPlease
1034-
ASYNC_AS_THREAD = YesPlease
10351033
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/win32
10361034
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
10371035
COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \
@@ -1344,9 +1342,6 @@ ifdef NO_PTHREADS
13441342
else
13451343
EXTLIBS += $(PTHREAD_LIBS)
13461344
LIB_OBJS += thread-utils.o
1347-
ifdef ASYNC_AS_THREAD
1348-
BASIC_CFLAGS += -DASYNC_AS_THREAD
1349-
endif
13501345
endif
13511346

13521347
ifdef DIR_HAS_BSD_GROUP_SEMANTICS

run-command.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,18 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
447447
return run_command(&cmd);
448448
}
449449

450-
#ifdef ASYNC_AS_THREAD
450+
#ifndef NO_PTHREADS
451451
static pthread_t main_thread;
452452
static int main_thread_set;
453453
static pthread_key_t async_key;
454454

455455
static void *run_thread(void *data)
456456
{
457457
struct async *async = data;
458+
intptr_t ret;
458459

459460
pthread_setspecific(async_key, async);
460-
461-
intptr_t ret = async->proc(async->proc_in, async->proc_out, async->data);
461+
ret = async->proc(async->proc_in, async->proc_out, async->data);
462462
return (void *)ret;
463463
}
464464

@@ -521,7 +521,7 @@ int start_async(struct async *async)
521521
else
522522
proc_out = -1;
523523

524-
#ifndef ASYNC_AS_THREAD
524+
#ifdef NO_PTHREADS
525525
/* Flush stdio before fork() to avoid cloning buffers */
526526
fflush(NULL);
527527

@@ -590,7 +590,7 @@ int start_async(struct async *async)
590590

591591
int finish_async(struct async *async)
592592
{
593-
#ifndef ASYNC_AS_THREAD
593+
#ifdef NO_PTHREADS
594594
return wait_or_whine(async->pid, "child process", 0);
595595
#else
596596
void *ret = (void *)(intptr_t)(-1);

run-command.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef RUN_COMMAND_H
22
#define RUN_COMMAND_H
33

4-
#ifdef ASYNC_AS_THREAD
4+
#ifndef NO_PTHREADS
55
#include <pthread.h>
66
#endif
77

@@ -78,7 +78,7 @@ struct async {
7878
void *data;
7979
int in; /* caller writes here and closes it */
8080
int out; /* caller reads from here and closes it */
81-
#ifndef ASYNC_AS_THREAD
81+
#ifdef NO_PTHREADS
8282
pid_t pid;
8383
#else
8484
pthread_t tid;

0 commit comments

Comments
 (0)