public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: FIFO: improve the check for the listen_client thread
@ 2019-05-09 18:52 Ken Brown
0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2019-05-09 18:52 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=102571f85da6344591848df2c8ebc200699cb031
commit 102571f85da6344591848df2c8ebc200699cb031
Author: Ken Brown <kbrown@cornell.edu>
Date: Thu May 9 12:28:21 2019 -0400
Cygwin: FIFO: improve the check for the listen_client thread
Add a method fhandler_fifo::check_listen_client_thread that checks
whether the thread is running. Use it in raw_read instead of just
testing the handle listen_client_thr.
Diff:
---
winsup/cygwin/fhandler.h | 1 +
winsup/cygwin/fhandler_fifo.cc | 34 ++++++++++++++++++++++++++++++++--
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index f4c0f03..969b23a 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1274,6 +1274,7 @@ class fhandler_fifo: public fhandler_base
void delete_client_handler (int);
bool listen_client ();
int stop_listen_client ();
+ int check_listen_client_thread ();
void record_connection (fifo_client_handler&);
public:
fhandler_fifo ();
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 1b1b3c7..4bf157d 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -744,13 +744,43 @@ retry:
return eof;
}
+/* Is the lct running? */
+int
+fhandler_fifo::check_listen_client_thread ()
+{
+ int ret = 0;
+
+ if (listen_client_thr)
+ {
+ DWORD waitret = WaitForSingleObject (listen_client_thr, 0);
+ switch (waitret)
+ {
+ case WAIT_OBJECT_0:
+ CloseHandle (listen_client_thr);
+ break;
+ case WAIT_TIMEOUT:
+ ret = 1;
+ break;
+ default:
+ debug_printf ("WaitForSingleObject failed, %E");
+ ret = -1;
+ __seterrno ();
+ CloseHandle (listen_client_thr);
+ break;
+ }
+ }
+ return ret;
+}
+
void __reg3
fhandler_fifo::raw_read (void *in_ptr, size_t& len)
{
size_t orig_len = len;
- /* Start the listen_client thread if necessary (shouldn't be). */
- if (!listen_client_thr && !listen_client ())
+ /* Make sure the lct is running. */
+ int res = check_listen_client_thread ();
+ debug_printf ("lct status %d", res);
+ if (res < 0 || (res == 0 && !listen_client ()))
goto errout;
while (1)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-05-09 18:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-09 18:52 [newlib-cygwin] Cygwin: FIFO: improve the check for the listen_client thread Ken Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).