* python/python.c: Include "serial.h".
authorPedro Alves <palves@redhat.com>
Fri, 20 Aug 2010 18:52:11 +0000 (18:52 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 20 Aug 2010 18:52:11 +0000 (18:52 +0000)
(gdbpy_event_fds): Change type to `struct serial *' a array from
int array.
(gdbpy_run_events): Change parameters.  Use serial_readchar in
place of read.
(gdbpy_post_event): Use serial_write in place of write.
(gdbpy_initialize_events): Use serial_pipe instead of pipe, and
serial_async in place of add_file_handler.

gdb/ChangeLog
gdb/python/python.c

index c999f446139d8e97030d0bf70930cb8684eb38c0..e74be9726b7190142a0eb7ec57d217dfb21b6c68 100644 (file)
@@ -1,3 +1,14 @@
+2010-08-20  Pedro Alves  <pedro@codesourcery.com>
+
+       * python/python.c: Include "serial.h".
+       (gdbpy_event_fds): Change type to `struct serial *' a array from
+       int array.
+       (gdbpy_run_events): Change parameters.  Use serial_readchar in
+       place of read.
+       (gdbpy_post_event): Use serial_write in place of write.
+       (gdbpy_initialize_events): Use serial_pipe instead of pipe, and
+       serial_async in place of add_file_handler.
+
 2010-08-20  Pedro Alves  <pedro@codesourcery.com>
 
        * serial.h (gdb_pipe, serial_pipe): Declare.
index 0f39120b18b086bb14c6d3f618e78e2d19056056..1cd1503fe25380df78e9bb0d1be1592714b6a316 100644 (file)
@@ -29,6 +29,7 @@
 #include "language.h"
 #include "exceptions.h"
 #include "event-loop.h"
+#include "serial.h"
 
 #include <ctype.h>
 
@@ -568,23 +569,25 @@ static struct gdbpy_event **gdbpy_event_list_end;
 
 /* We use a file handler, and not an async handler, so that we can
    wake up the main thread even when it is blocked in poll().  */
-static int gdbpy_event_fds[2];
+static struct serial *gdbpy_event_fds[2];
 
 /* The file handler callback.  This reads from the internal pipe, and
    then processes the Python event queue.  This will always be run in
    the main gdb thread.  */
+
 static void
-gdbpy_run_events (int err, gdb_client_data ignore)
+gdbpy_run_events (struct serial *scb, void *context)
 {
   struct cleanup *cleanup;
-  char buffer[100];
   int r;
 
   cleanup = ensure_python_env (get_current_arch (), current_language);
 
-  /* Just read whatever is available on the fd.  It is relatively
-     harmless if there are any bytes left over.  */
-  r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
+  /* Flush the fd.  Do this before flushing the events list, so that
+     any new event post afterwards is sure to re-awake the event
+     loop.  */
+  while (serial_readchar (gdbpy_event_fds[0], 0) >= 0)
+    ;
 
   while (gdbpy_event_list)
     {
@@ -640,7 +643,8 @@ gdbpy_post_event (PyObject *self, PyObject *args)
   if (wakeup)
     {
       char c = 'q';            /* Anything. */
-      if (write (gdbpy_event_fds[1], &c, 1) != 1)
+
+      if (serial_write (gdbpy_event_fds[1], &c, 1))
         return PyErr_SetFromErrno (PyExc_IOError);
     }
 
@@ -651,10 +655,10 @@ gdbpy_post_event (PyObject *self, PyObject *args)
 static void
 gdbpy_initialize_events (void)
 {
-  if (!pipe (gdbpy_event_fds))
+  if (serial_pipe (gdbpy_event_fds) == 0)
     {
       gdbpy_event_list_end = &gdbpy_event_list;
-      add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
+      serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL);
     }
 }
 
This page took 0.029183 seconds and 4 git commands to generate.