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>
Johannes Sixt committed
Mar 9, 2010 at 21:00 UTC
f6b6098316192475ff0b3fa2ba894d7e555bdfac
4 files changed
+10
-14
Documentation/technical/api-run-command.txt
+3
-2
@@ -231,8 +231,9 @@ The function pointer in .proc has the following signature:
231
232
233
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:
237
238
. It cannot change the program's state (global variables, environment,
239
etc.) in a way that the caller notices; in other words, .in and .out
Makefile
-5
@@ -979,7 +979,6 @@ ifeq ($(uname_S),Windows)
979
NO_CURL = YesPlease
980
NO_PYTHON = YesPlease
981
BLK_SHA1 = YesPlease
982
- ASYNC_AS_THREAD = YesPlease
982
983
CC = compat/vcbuild/scripts/clink.pl
984
AR = compat/vcbuild/scripts/lib.pl
@@ -1031,7 +1030,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
1030
NO_REGEX = YesPlease
1031
NO_PYTHON = YesPlease
1032
BLK_SHA1 = YesPlease
1034
- ASYNC_AS_THREAD = YesPlease
1033
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/win32
1034
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
1035
COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \
@@ -1344,9 +1342,6 @@ ifdef NO_PTHREADS
1342
else
1343
EXTLIBS += $(PTHREAD_LIBS)
1344
LIB_OBJS += thread-utils.o
1347
-ifdef ASYNC_AS_THREAD
1348
- BASIC_CFLAGS += -DASYNC_AS_THREAD
1349
-endif
1345
endif
1346
1347
ifdef DIR_HAS_BSD_GROUP_SEMANTICS
run-command.c
+5
-5
@@ -447,7 +447,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
447
return run_command(&cmd);
448
}
449
450
-#ifdef ASYNC_AS_THREAD
450
+#ifndef NO_PTHREADS
451
static pthread_t main_thread;
452
static int main_thread_set;
453
static pthread_key_t async_key;
@@ -455,10 +455,10 @@ static pthread_key_t async_key;
455
static void *run_thread(void *data)
456
{
457
struct async *async = data;
458
+ intptr_t ret;
459
460
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);
462
return (void *)ret;
463
}
464
@@ -521,7 +521,7 @@ int start_async(struct async *async)
521
else
522
proc_out = -1;
523
524
-#ifndef ASYNC_AS_THREAD
524
+#ifdef NO_PTHREADS
525
/* Flush stdio before fork() to avoid cloning buffers */
526
fflush(NULL);
527
@@ -590,7 +590,7 @@ error:
590
591
int finish_async(struct async *async)
592
{
593
-#ifndef ASYNC_AS_THREAD
593
+#ifdef NO_PTHREADS
594
return wait_or_whine(async->pid, "child process", 0);
595
#else
596
void *ret = (void *)(intptr_t)(-1);
run-command.h
+2
-2
@@ -1,7 +1,7 @@
1
#ifndef RUN_COMMAND_H
2
#define RUN_COMMAND_H
3
4
-#ifdef ASYNC_AS_THREAD
4
+#ifndef NO_PTHREADS
5
#include <pthread.h>
6
#endif
7
@@ -78,7 +78,7 @@ struct async {
78
void *data;
79
int in; /* caller writes here and closes it */
80
int out; /* caller reads from here and closes it */
81
-#ifndef ASYNC_AS_THREAD
81
+#ifdef NO_PTHREADS
82
pid_t pid;
83
#else
84
pthread_t tid;