Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-11-03 06:32:27 +0300
committerChristopher Faylor <me@cgf.cx>2001-11-03 06:32:27 +0300
commit243a041bd0164aa62813ac4ba5a1a02eb2db455b (patch)
treeaf591a485215fcd4578be09cfabe6ff75b0782fe /winsup/cygwin/select.cc
parent01432054cb24122d300f109d4d252a9c95835a9b (diff)
* dll_init.h (class dll_list): Reorder functions to avoid compiler "can't
inline" warnings. * security.h (class cygsid): Ditto. * sigproc.cc (get_proc_lock): Ditto. * sigproc.h (class sigframe): Ditto. * sync.h (class muto): Ditto. * fhandler.h (fhandler_base::get_guard): Actually MAKE virtual as previously indicated. * pipe.cc (make_pipe): Remove extraneous set_errno. * syscalls.cc (_open): Ditto. * select.cc (peek_pipe): Need to check that there is still something to read from the pipe after acquiring the mutex since another process/thread could have eaten the input before we got to acquiring the lock. (Thanks to Nick Duffek for this inspiration.)
Diffstat (limited to 'winsup/cygwin/select.cc')
-rw-r--r--winsup/cygwin/select.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 1ba3ef3d8..78d1aaabe 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -389,7 +389,7 @@ peek_pipe (select_record *s, int ignra)
fhandler_base *fh = s->fh;
HANDLE h;
- HANDLE guard_mutex = s->fh->get_guard ();
+ HANDLE guard_mutex = fh->get_guard ();
set_handle_or_return_if_not_open (h, s);
/* Don't perform complicated tests if we don't need to. */
@@ -438,12 +438,23 @@ peek_pipe (select_record *s, int ignra)
select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ());
n = -1;
}
- else if (n && guard_mutex
- && WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0)
+ else if (n && guard_mutex)
{
- select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (),
- guard_mutex);
- n = 0;
+ if (WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0)
+ {
+ select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (),
+ guard_mutex);
+ n = 0;
+ }
+ /* 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)