From patchwork Fri Mar 18 19:18:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 11404 Received: (qmail 57164 invoked by alias); 18 Mar 2016 19:26:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 57092 invoked by uid 89); 18 Mar 2016 19:26:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 spammy=35, 6, Wake, 35, 7, Anything X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Mar 2016 19:26:30 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 6D035C00F21A for ; Fri, 18 Mar 2016 19:18:44 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IJIYk8028091 for ; Fri, 18 Mar 2016 15:18:43 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 10/30] Make Python use a struct serial event Date: Fri, 18 Mar 2016 19:18:14 +0000 Message-Id: <1458328714-4938-11-git-send-email-palves@redhat.com> In-Reply-To: <1458328714-4938-1-git-send-email-palves@redhat.com> References: <1458328714-4938-1-git-send-email-palves@redhat.com> From: Pedro Alves Now that we have an abstract for wakeable events, use it instead of a (heavier) serial pipe. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * python/python.c: Include "ser-event.h". (gdbpy_event_fds): Delete. (gdbpy_serial_event): New. (gdbpy_run_events): Change prototype. Use serial_event_clear instead of serial_readchar. (gdbpy_post_event): Use serial_event_set instead of serial_write. (gdbpy_initialize_events): Use make_serial_event instead of serial_pipe. --- gdb/python/python.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/gdb/python/python.c b/gdb/python/python.c index 7202105..ab3aa0a 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -35,6 +35,7 @@ #include "cli/cli-utils.h" #include #include "location.h" +#include "ser-event.h" /* Declared constants and enum for python stack printing. */ static const char python_excp_none[] = "none"; @@ -922,26 +923,25 @@ static struct gdbpy_event *gdbpy_event_list; /* The final link of the event list. */ 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 struct serial *gdbpy_event_fds[2]; +/* So that we can wake up the main thread even when it is blocked in + poll(). */ +static struct serial_event *gdbpy_serial_event; /* 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 (struct serial *scb, void *context) +gdbpy_run_events (int error, gdb_client_data client_data) { struct cleanup *cleanup; cleanup = ensure_python_env (get_current_arch (), current_language); - /* Flush the fd. Do this before flushing the events list, so that - any new event post afterwards is sure to re-awake the event + /* Clear the event 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) - ; + serial_event_clear (gdbpy_serial_event); while (gdbpy_event_list) { @@ -999,12 +999,7 @@ gdbpy_post_event (PyObject *self, PyObject *args) /* Wake up gdb when needed. */ if (wakeup) - { - char c = 'q'; /* Anything. */ - - if (serial_write (gdbpy_event_fds[1], &c, 1)) - return PyErr_SetFromErrno (PyExc_IOError); - } + serial_event_set (gdbpy_serial_event); Py_RETURN_NONE; } @@ -1013,11 +1008,11 @@ gdbpy_post_event (PyObject *self, PyObject *args) static int gdbpy_initialize_events (void) { - if (serial_pipe (gdbpy_event_fds) == 0) - { - gdbpy_event_list_end = &gdbpy_event_list; - serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL); - } + gdbpy_event_list_end = &gdbpy_event_list; + + gdbpy_serial_event = make_serial_event (); + add_file_handler (serial_event_fd (gdbpy_serial_event), + gdbpy_run_events, NULL); return 0; }