Reimplement async procedures using pthreads

On Windows, async procedures have always been run in threads, and the
implementation used Windows specific APIs. Rewrite the code to use pthreads.

A new configuration option is introduced so that the threaded implementation
can also be used on POSIX systems. Since this option is intended only as
playground on POSIX, but is mandatory on Windows, the option is not
documented.

One detail is that on POSIX it is necessary to set FD_CLOEXEC on the pipe
handles. On Windows, this is not needed because pipe handles are not
inherited to child processes, and the new calls to set_cloexec() are
effectively no-ops.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Sixt
2010-03-06 16:40:42 +01:00
committed by Junio C Hamano
parent 912b26324d
commit 200a76b74d
3 changed files with 34 additions and 20 deletions

View File

@ -1,6 +1,10 @@
#ifndef RUN_COMMAND_H
#define RUN_COMMAND_H
#ifdef ASYNC_AS_THREAD
#include <pthread.h>
#endif
struct child_process {
const char **argv;
pid_t pid;
@ -74,10 +78,10 @@ struct async {
void *data;
int in; /* caller writes here and closes it */
int out; /* caller reads from here and closes it */
#ifndef WIN32
#ifndef ASYNC_AS_THREAD
pid_t pid;
#else
HANDLE tid;
pthread_t tid;
int proc_in;
int proc_out;
#endif