diff options
author | Christopher Faylor <me@cgf.cx> | 2007-07-07 21:00:33 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2007-07-07 21:00:33 +0400 |
commit | d9c0e3ec35b3a087ea68f528967765c2ee6a0dca (patch) | |
tree | dfbb5b49470a1683e12a1579005f99d66feb588a /winsup/cygwin/select.cc | |
parent | dee55888399728d1b4652e1a369e0f62a77c1111 (diff) |
Preliminary change to make fifos/pipes interruptible and fifos reliable.
* dtable.cc (dtable::find_fifo): Eliminate definition.
* dtable.h (dtable::find_fifo): Ditto for declaration.
* fhandler.cc (fhandler_base::raw_read): Remove pipe-specific stuff.
(fhandler_base::fhandler_base): Ditto.
(fhandler_base::close): Handle overlapped I/O structure if appropriate.
(fhandler_base::dup): Ditto.
(fhandler_base::fork_fixup): Ditto.
(fhandler_base::setup_overlapped): Define new function.
(fhandler_base::destroy_overlapped): Ditto.
(fhandler_base::wait_overlapped): Ditto.
(fhandler_base::read_overlapped): Ditto.
(fhandler_base::write_overlapped): Ditto.
* fhandler.h (fhandler_base::get_overlapped): Declare new function.
(fhandler_base::setup_overlapped): Ditto.
(fhandler_base::destroy_overlapped): Ditto.
(fhandler_base::wait_overlapped): Ditto.
(fhandler_base::read_overlapped): Ditto.
(fhandler_base::write_overlapped): Ditto.
(fhandler_base::get_guard): Eliminate.
(fhandler_pipe::*): Rework to eliminate most Win9x related cruft, removing many
variables and defining a new overlapped capability.
(fhandler_fifo::*): Ditto.
(fifo_state): Declare new enum.
* fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Remove old Win9x stuff.
Initialize overlapped handle to NULL.
(fhandler_fifo::set_use): Eliminate.
(fhandler_fifo::open_nonserver): Define.
(fhandler_fifo::open): Rework to use named pipes and overlapped I/O.
(fhandler_fifo::wait): Define new function to wait for named pipe connection.
(fhandler_fifo::read): Rework to use wait() and new overlapped I/O
functionality.
(fhandler_fifo::write): Ditto.
(fhandler_fifo::dup): Eliminate.
* pinfo.cc (commune_process): Remove fifo handling.
(_pinfo::commune_request): Ditto.
* pinfo.h (picom): Ditto.
* pipe.cc (fhandler_pipe::fhandler_pipe): Remove Win9x stuff. Initialize
overlapped handle to NULL.
(fhandler_pipe::open): Eliminate Win9x stuff.
(fhandler_pipe::set_close_on_exec): Eliminate.
(read_pipe): Eliminate.
(fhandler_pipe::close): Ditto.
(fhandler_pipe::fixup_after_exec): Ditto.
(fhandler_pipe::fixup_in_child): Ditto.
(fhandler_pipe::read): Rework to use overlapped I/O.
(fhandler_pipe::write): New function using overlapped I/O.
(fhandler_pipe::dup): Rework to eliminate Win9x stuff.
(fhandler_pipe::create_selectable): Rework to eliminate Win9x and use
overlapped I/O.
* select.cc (peek_pipe): Rework to eliminate Win9x stuff and use overlapped
I/O.
(fhandler_base::ready_for_read): Ditto.
Diffstat (limited to 'winsup/cygwin/select.cc')
-rw-r--r-- | winsup/cygwin/select.cc | 56 |
1 files changed, 1 insertions, 55 deletions
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 3c72e8ac9..5711c1bf3 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -429,15 +429,6 @@ peek_pipe (select_record *s, bool from_select) HANDLE h; set_handle_or_return_if_not_open (h, s); - /* pipes require a guard mutex to guard against the situation where multiple - readers are attempting to read from the same pipe. In this scenario, it - is possible for PeekNamedPipe to report available data to two readers but - only one will actually get the data. This will result in the other reader - entering fhandler_base::raw_read and blocking indefinitely in an interruptible - state. This causes things like "make -j2" to hang. So, for the non-select case - we use the pipe mutex, if it is available. */ - HANDLE guard_mutex = from_select ? NULL : fh->get_guard (); - /* Don't perform complicated tests if we don't need to. */ if (!s->read_selected && !s->except_selected) goto out; @@ -484,30 +475,9 @@ peek_pipe (select_record *s, bool from_select) select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ()); n = -1; } - else if (!n || !guard_mutex) - /* no guard mutex or nothing to read from the pipe. */; - else if (WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0) - { - select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (), - guard_mutex); - n = 0; - } - else - { - /* Now that we have the mutex, make sure that no one else has snuck - in and grabbed the data that we originally saw. */ - if (!PeekNamedPipe (h, NULL, 0, NULL, (DWORD *) &n, NULL)) - { - select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ()); - n = -1; - } - if (n <= 0) - ReleaseMutex (guard_mutex); /* Oops. We lost the race. */ - } if (n < 0) { - fh->set_eof (); /* Flag that other end of pipe is gone */ select_printf ("%s, n %d", fh->get_name (), n); if (s->except_selected) gotone += s->except_ready = true; @@ -546,10 +516,6 @@ out: /* FIXME: This code is not quite correct. There's no better solution so far but to always treat the write side of the pipe as writable. */ - /* We don't worry about the guard mutex, because that only applies - when from_select is false, and peek_pipe is never called that - way for writes. */ - IO_STATUS_BLOCK iosb = {0}; FILE_PIPE_LOCAL_INFORMATION fpli = {0}; @@ -685,25 +651,8 @@ fhandler_pipe::ready_for_read (int fd, DWORD howlong) int res; if (!howlong) res = fhandler_base::ready_for_read (fd, howlong); - else if (!get_guard ()) - res = 1; else - { - const HANDLE w4[2] = {get_guard (), signal_arrived}; - switch (WaitForMultipleObjects (2, w4, 0, INFINITE)) - { - case WAIT_OBJECT_0: - res = 1; - break; - case WAIT_OBJECT_0 + 1: - set_sig_errno (EINTR); - res = 0; - break; - default: - __seterrno (); - res = 0; - } - } + res = 1; return res; } @@ -1202,9 +1151,6 @@ fhandler_base::ready_for_read (int fd, DWORD howlong) } } - if (get_guard () && !avail && me.read_ready) - ReleaseMutex (get_guard ()); - select_printf ("read_ready %d, avail %d", me.read_ready, avail); return avail; } |