This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH 02/14] Cygwin: FIFO: hit_eof: add a call to fifo_client_lock
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Sun, 14 Apr 2019 19:15:56 +0000
- Subject: [PATCH 02/14] Cygwin: FIFO: hit_eof: add a call to fifo_client_lock
- References: <20190414191543.3218-1-kbrown@cornell.edu>
The second check of nconnected needs to be protected by a lock as well
as the first.
---
winsup/cygwin/fhandler_fifo.cc | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 901696444..70551ebac 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -705,15 +705,20 @@ fhandler_fifo::raw_write (const void *ptr, size_t len)
bool
fhandler_fifo::hit_eof ()
{
- fifo_client_lock ();
- bool eof = (nconnected == 0);
- fifo_client_unlock ();
- if (eof)
- {
- /* Give the listen_client thread time to catch up, then recheck. */
- Sleep (1);
+ bool eof;
+ bool retry = true;
+
+retry:
+ fifo_client_lock ();
eof = (nconnected == 0);
- }
+ fifo_client_unlock ();
+ if (eof && retry)
+ {
+ retry = false;
+ /* Give the listen_client thread time to catch up. */
+ Sleep (1);
+ goto retry;
+ }
return eof;
}
--
2.17.0