This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] fix up "target remote |" on mingw


The last two patches to this file were my fixes to select infrastructure, on
24th April, and Jim's support for "target remote |" on 25th April.  The two
patches crossed in the night :-(  This adjusts the pipe code to work like
the others, especially important because of the amount of code shared with
the console handler.

Tested on Windows and checked in.  Thanks to Sandra Loosemore for tracking
down that it had broken.

-- 
Daniel Jacobowitz
CodeSourcery

2006-10-10  Daniel Jacobowitz  <dan@codesourcery.com>

	* ser-mingw.c (free_pipe_state, pipe_wait_handle): Update
	for changes to pipe_select_thread.
	(pipe_done_wait_handle): New.
	(_initialize_ser_windows): Reference it.

Index: ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.3
diff -u -p -r1.3 ser-mingw.c
--- ser-mingw.c	25 Apr 2006 18:02:13 -0000	1.3
+++ ser-mingw.c	6 Oct 2006 19:58:03 -0000
@@ -658,16 +658,19 @@ free_pipe_state (struct pipe_state *ps)
   int saved_errno = errno;
 
   if (ps->wait.read_event != INVALID_HANDLE_VALUE)
-    CloseHandle (ps->wait.read_event);
-  if (ps->wait.except_event != INVALID_HANDLE_VALUE)
-    CloseHandle (ps->wait.except_event);
-  if (ps->wait.start_select != INVALID_HANDLE_VALUE)
-    CloseHandle (ps->wait.start_select);
-
-  /* If we have a select thread running, let the select thread free
-     the stop event.  */
-  if (ps->wait.stop_select != INVALID_HANDLE_VALUE)
-    SetEvent (ps->wait.stop_select);
+    {
+      SetEvent (ps->wait.exit_select);
+
+      WaitForSingleObject (ps->wait.thread, INFINITE);
+
+      CloseHandle (ps->wait.start_select);
+      CloseHandle (ps->wait.stop_select);
+      CloseHandle (ps->wait.exit_select);
+      CloseHandle (ps->wait.have_stopped);
+
+      CloseHandle (ps->wait.read_event);
+      CloseHandle (ps->wait.except_event);
+    }
 
   /* Close the pipe to the child.  We must close the pipe before
      calling pex_free because pex_free will wait for the child to exit
@@ -812,9 +815,16 @@ pipe_wait_handle (struct serial *scb, HA
     {
       DWORD threadId;
 
-      /* Create auto reset events to wake and terminate the select thread.  */
+      /* Create auto reset events to wake, stop, and exit the select
+	 thread.  */
       ps->wait.start_select = CreateEvent (0, FALSE, FALSE, 0);
       ps->wait.stop_select = CreateEvent (0, FALSE, FALSE, 0);
+      ps->wait.exit_select = CreateEvent (0, FALSE, FALSE, 0);
+
+      /* Create a manual reset event to signal whether the thread is
+	 stopped.  This must be manual reset, because we may wait on
+	 it multiple times without ever starting the thread.  */
+      ps->wait.have_stopped = CreateEvent (0, TRUE, FALSE, 0);
 
       /* Create our own events to report read and exceptions separately.
 	 The exception event is currently never used.  */
@@ -825,15 +835,30 @@ pipe_wait_handle (struct serial *scb, HA
       CreateThread (NULL, 0, pipe_select_thread, scb, 0, &threadId);
     }
 
+  *read = ps->wait.read_event;
+  *except = ps->wait.except_event;
+
+  /* Start from a blank state.  */
   ResetEvent (ps->wait.read_event);
   ResetEvent (ps->wait.except_event);
+  ResetEvent (ps->wait.stop_select);
 
+  /* Start the select thread.  */
   SetEvent (ps->wait.start_select);
-
-  *read = ps->wait.read_event;
-  *except = ps->wait.except_event;
 }
 
+static void
+pipe_done_wait_handle (struct serial *scb)
+{
+  struct pipe_state *ps = scb->state;
+
+  /* Have we allocated our events yet?  */
+  if (ps->wait.read_event == INVALID_HANDLE_VALUE)
+    return;
+
+  SetEvent (ps->wait.stop_select);
+  WaitForSingleObject (ps->wait.have_stopped, INFINITE);
+}
 
 struct net_windows_state
 {
@@ -1133,6 +1158,7 @@ _initialize_ser_windows (void)
   ops->read_prim = pipe_windows_read;
   ops->write_prim = pipe_windows_write;
   ops->wait_handle = pipe_wait_handle;
+  ops->done_wait_handle = pipe_done_wait_handle;
 
   serial_add_interface (ops);
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]