Skip to content

Commit

Permalink
Enable threaded async procedures whenever pthreads is available
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Mar 10, 2010
1 parent 0ea1c89 commit f6b6098
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Documentation/technical/api-run-command.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ The function pointer in .proc has the following signature:


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

. It cannot change the program's state (global variables, environment,
etc.) in a way that the caller notices; in other words, .in and .out
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,6 @@ ifeq ($(uname_S),Windows)
NO_CURL = YesPlease
NO_PYTHON = YesPlease
BLK_SHA1 = YesPlease
ASYNC_AS_THREAD = YesPlease

CC = compat/vcbuild/scripts/clink.pl
AR = compat/vcbuild/scripts/lib.pl
Expand Down Expand Up @@ -1031,7 +1030,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
NO_REGEX = YesPlease
NO_PYTHON = YesPlease
BLK_SHA1 = YesPlease
ASYNC_AS_THREAD = YesPlease
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/win32
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \
Expand Down Expand Up @@ -1344,9 +1342,6 @@ ifdef NO_PTHREADS
else
EXTLIBS += $(PTHREAD_LIBS)
LIB_OBJS += thread-utils.o
ifdef ASYNC_AS_THREAD
BASIC_CFLAGS += -DASYNC_AS_THREAD
endif
endif

ifdef DIR_HAS_BSD_GROUP_SEMANTICS
Expand Down
10 changes: 5 additions & 5 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,18 +447,18 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
return run_command(&cmd);
}

#ifdef ASYNC_AS_THREAD
#ifndef NO_PTHREADS
static pthread_t main_thread;
static int main_thread_set;
static pthread_key_t async_key;

static void *run_thread(void *data)
{
struct async *async = data;
intptr_t ret;

pthread_setspecific(async_key, async);

intptr_t ret = async->proc(async->proc_in, async->proc_out, async->data);
ret = async->proc(async->proc_in, async->proc_out, async->data);
return (void *)ret;
}

Expand Down Expand Up @@ -521,7 +521,7 @@ int start_async(struct async *async)
else
proc_out = -1;

#ifndef ASYNC_AS_THREAD
#ifdef NO_PTHREADS
/* Flush stdio before fork() to avoid cloning buffers */
fflush(NULL);

Expand Down Expand Up @@ -590,7 +590,7 @@ int start_async(struct async *async)

int finish_async(struct async *async)
{
#ifndef ASYNC_AS_THREAD
#ifdef NO_PTHREADS
return wait_or_whine(async->pid, "child process", 0);
#else
void *ret = (void *)(intptr_t)(-1);
Expand Down
4 changes: 2 additions & 2 deletions run-command.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RUN_COMMAND_H
#define RUN_COMMAND_H

#ifdef ASYNC_AS_THREAD
#ifndef NO_PTHREADS
#include <pthread.h>
#endif

Expand Down Expand Up @@ -78,7 +78,7 @@ struct async {
void *data;
int in; /* caller writes here and closes it */
int out; /* caller reads from here and closes it */
#ifndef ASYNC_AS_THREAD
#ifdef NO_PTHREADS
pid_t pid;
#else
pthread_t tid;
Expand Down

0 comments on commit f6b6098

Please sign in to comment.