From 1d380f593ae54513419a7e7f31817fc23a5e69b9 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 11 Dec 2002 04:00:04 +0000 Subject: * cygthread.h (cygthread::stack_ptr): New element. (cygthread::detach): Accept a "wait_for_signal" argument. (cygthread::terminate_thread): New function. * cygthread.cc (cygthread::stub): Set stack pointer argument. (cygthread::terminate_thread): New function. Forcibly terminate thread. (cygthread::detach): Optionally wait for signals and kill thread when signal arrives. * exceptions.cc (signal_exit): Set signal_arrived prior to exiting to wake up anything blocking on signals. * fhandler.h (fhandler_base::set_r_no_interrupt): Change to accept bool argument. (fhandler_pipe::ready_for_read): Declare. * pipe.cc (pipeargs): New structure. (read_pipe): New thread stub wrapper for normal pipe read. (fhandler_pipe::read): Modify to call reader in a cygthread, terminating on signal, as appropriate. * select.cc (fhandler_pipe::ready_for_read): Define new function. --- winsup/cygwin/pipe.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'winsup/cygwin/pipe.cc') diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index fe712e25e..49093728c 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -22,6 +22,7 @@ details. */ #include "cygheap.h" #include "thread.h" #include "pinfo.h" +#include "cygthread.h" static unsigned pipecount; static const NO_COPY char pipeid_fmt[] = "stupid_pipe.%u.%u"; @@ -50,14 +51,36 @@ fhandler_pipe::set_close_on_exec (int val) set_inheritance (writepipe_exists, val); } +struct pipeargs +{ + fhandler_base *fh; + void *ptr; + size_t len; + int res; +}; + +static DWORD WINAPI +read_pipe (void *arg) +{ + pipeargs *pi = (pipeargs *) arg; + pi->res = pi->fh->fhandler_base::read (pi->ptr, pi->len); + return 0; +} + int __stdcall fhandler_pipe::read (void *in_ptr, size_t in_len) { if (broken_pipe) return 0; - int res = this->fhandler_base::read (in_ptr, in_len); + pipeargs pi; + pi.fh = this; + pi.ptr = in_ptr; + pi.len = in_len; + pi.res = -1; + cygthread *th = new cygthread (read_pipe, &pi, "read_pipe"); + th->detach (1); (void) ReleaseMutex (guard); - return res; + return pi.res; } int fhandler_pipe::close () -- cgit v1.2.3