https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6e7e82fee758695c3e46618038325d41e44fbef5

commit 6e7e82fee758695c3e46618038325d41e44fbef5
Author: Ken Brown <kbr...@cornell.edu>
Date:   Thu Jun 20 15:14:47 2019 -0400

    Cygwin: FIFO: remove fifo_client_handler::connect_evt
    
    It's not needed.  Instead just create and use an event in
    fhandler_fifo::listen_client_thread.

Diff:
---
 winsup/cygwin/fhandler.h       |  3 +--
 winsup/cygwin/fhandler_fifo.cc | 28 ++++++++++++++--------------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 293a3e0..185de98 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1253,8 +1253,7 @@ struct fifo_client_handler
 {
   fhandler_base *fh;
   fifo_client_connect_state state;
-  HANDLE connect_evt;
-  fifo_client_handler () : fh (NULL), state (fc_unknown), connect_evt (NULL) {}
+  fifo_client_handler () : fh (NULL), state (fc_unknown) {}
   int close ();
 /* Returns FILE_PIPE_DISCONNECTED_STATE, FILE_PIPE_LISTENING_STATE,
    FILE_PIPE_CONNECTED_STATE, FILE_PIPE_CLOSING_STATE,
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index b755544..a060cb3 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -231,8 +231,6 @@ fhandler_fifo::add_client_handler ()
       set_errno (EMFILE);
       goto out;
     }
-  if (!(fc.connect_evt = create_event ()))
-    goto out;
   if (!(fh = build_fh_dev (dev ())))
     {
       set_errno (EMFILE);
@@ -304,15 +302,16 @@ fhandler_fifo::record_connection (fifo_client_handler& fc)
   nconnected++;
   fc.fh->set_nonblocking (true);
   set_pipe_non_blocking (fc.fh->get_handle (), true);
-  HANDLE evt = InterlockedExchangePointer (&fc.connect_evt, NULL);
-  if (evt)
-    CloseHandle (evt);
 }
 
 DWORD
 fhandler_fifo::listen_client_thread ()
 {
   DWORD ret = -1;
+  HANDLE evt;
+
+  if (!(evt = create_event ()))
+    goto out;
 
   while (1)
     {
@@ -353,12 +352,11 @@ fhandler_fifo::listen_client_thread ()
       NTSTATUS status;
       IO_STATUS_BLOCK io;
 
-      status = NtFsControlFile (fc.fh->get_handle (), fc.connect_evt,
-                               NULL, NULL, &io, FSCTL_PIPE_LISTEN,
-                               NULL, 0, NULL, 0);
+      status = NtFsControlFile (fc.fh->get_handle (), evt, NULL, NULL, &io,
+                               FSCTL_PIPE_LISTEN, NULL, 0, NULL, 0);
       if (status == STATUS_PENDING)
        {
-         HANDLE w[2] = { fc.connect_evt, lct_termination_evt };
+         HANDLE w[2] = { evt, lct_termination_evt };
          DWORD waitret = WaitForMultipleObjects (2, w, false, INFINITE);
          switch (waitret)
            {
@@ -384,6 +382,7 @@ fhandler_fifo::listen_client_thread ()
        case STATUS_SUCCESS:
        case STATUS_PIPE_CONNECTED:
          record_connection (fc);
+         ResetEvent (evt);
          break;
        case STATUS_THREAD_IS_TERMINATING:
          /* Force NtFsControlFile to complete.  Otherwise the next
@@ -431,9 +430,13 @@ fhandler_fifo::listen_client_thread ()
        }
     }
 out:
-  if (ret < 0)
-    debug_printf ("exiting lct with error, %E");
+  if (evt)
+    CloseHandle (evt);
   ResetEvent (read_ready);
+  if (ret < 0)
+    debug_printf ("exiting with error, %E");
+  else
+    debug_printf ("exiting without error");
   return ret;
 }
 
@@ -908,10 +911,7 @@ int
 fifo_client_handler::close ()
 {
   int res = 0;
-  HANDLE evt = InterlockedExchangePointer (&connect_evt, NULL);
 
-  if (evt)
-    CloseHandle (evt);
   if (fh)
     {
       res = fh->fhandler_base::close ();

Reply via email to