From patchwork Fri Jun 8 02:55:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27704 Received: (qmail 56157 invoked by alias); 8 Jun 2018 02:56:00 -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 56090 invoked by uid 89); 8 Jun 2018 02:55:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Tell, jumping, Hx-languages-length:3824, UD:server.h X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.179.26) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Jun 2018 02:55:51 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id B8F2D400C9B7A for ; Thu, 7 Jun 2018 21:55:49 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id R7Z7fnDnYPvAdR7Z7fzrcV; Thu, 07 Jun 2018 21:55:49 -0500 X-Authority-Reason: nr=8 Received: from 75-166-19-45.hlrn.qwest.net ([75.166.19.45]:34920 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fR7Z7-002GVZ-Dg; Thu, 07 Jun 2018 21:55:49 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Remove use of queue.h from gdbserver/event-loop.c Date: Thu, 7 Jun 2018 20:55:41 -0600 Message-Id: <20180608025541.14560-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fR7Z7-002GVZ-Dg X-Source-Sender: 75-166-19-45.hlrn.qwest.net (bapiya.Home) [75.166.19.45]:34920 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes a use of queue.h from gdbserver/event-loop.c, replacing it with std::queue. I was not completely sure whether std::queue is even that useful. Perhaps plain std::list could be used just as easily. Tested by the buildbot. gdb/gdbserver/ChangeLog 2018-06-07 Tom Tromey * event-loop.c (gdb_event, gdb_event_p): Remove typedefs. Don't declare queue. (event_queue): Use std::queue. (gdb_event_xfree): Remove. (initialize_event_loop, process_event, wait_for_event): Update. --- gdb/gdbserver/ChangeLog | 8 ++++++++ gdb/gdbserver/event-loop.c | 34 ++++++++++++---------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/gdb/gdbserver/event-loop.c b/gdb/gdbserver/event-loop.c index eec0bcf3af6..a3310a05c8b 100644 --- a/gdb/gdbserver/event-loop.c +++ b/gdb/gdbserver/event-loop.c @@ -19,7 +19,6 @@ /* Based on src/gdb/event-loop.c. */ #include "server.h" -#include "queue.h" #include #include "gdb_sys_time.h" @@ -30,8 +29,8 @@ #endif #include +#include -typedef struct gdb_event gdb_event; typedef int (event_handler_func) (gdb_fildes_t); /* Tell create_file_handler what events we are interested in. */ @@ -40,8 +39,7 @@ typedef int (event_handler_func) (gdb_fildes_t); #define GDB_WRITABLE (1<<2) #define GDB_EXCEPTION (1<<3) -/* Events are queued by calling 'QUEUE_enque (gdb_event_p, event_queue, - file_event_ptr)' and serviced later +/* Events are queued by on the event_queue and serviced later on by do_one_event. An event can be, for instance, a file descriptor becoming ready to be read. Servicing an event simply means that the procedure PROC will be called. We have 2 queues, @@ -52,14 +50,14 @@ typedef int (event_handler_func) (gdb_fildes_t); descriptor whose state change generated the event, plus doing other cleanups and such. */ -typedef struct gdb_event +struct gdb_event { /* Procedure to call to service this event. */ event_handler_func *proc; /* File descriptor that is ready. */ gdb_fildes_t fd; - } *gdb_event_p; + }; /* Information about each file descriptor we register with the event loop. */ @@ -89,9 +87,9 @@ typedef struct file_handler } file_handler; -DECLARE_QUEUE_P(gdb_event_p); -static QUEUE(gdb_event_p) *event_queue = NULL; -DEFINE_QUEUE_P(gdb_event_p); +typedef gdb::unique_xmalloc_ptr gdb_event_up; + +static std::queue> event_queue; /* Gdb_notifier is just a list of file descriptors gdb is interested in. These are the input file descriptor, and the target file @@ -146,18 +144,9 @@ static struct } callback_list; -/* Free EVENT. */ - -static void -gdb_event_xfree (struct gdb_event *event) -{ - xfree (event); -} - void initialize_event_loop (void) { - event_queue = QUEUE_alloc (gdb_event_p, gdb_event_xfree); } /* Process one event. If an event was processed, 1 is returned @@ -173,13 +162,14 @@ process_event (void) proc function could end up jumping out to the caller of this function. In that case, we would have on the event queue an event which has been processed, but not deleted. */ - if (!QUEUE_is_empty (gdb_event_p, event_queue)) + if (!event_queue.empty ()) { - gdb_event *event_ptr = QUEUE_deque (gdb_event_p, event_queue); + gdb_event_up event_ptr = std::move (event_queue.front ()); + event_queue.pop (); + event_handler_func *proc = event_ptr->proc; gdb_fildes_t fd = event_ptr->fd; - gdb_event_xfree (event_ptr); /* Now call the procedure associated with the event. */ if ((*proc) (fd)) return -1; @@ -522,7 +512,7 @@ wait_for_event (void) { gdb_event *file_event_ptr = create_file_event (file_ptr->fd); - QUEUE_enque (gdb_event_p, event_queue, file_event_ptr); + event_queue.emplace (file_event_ptr); } file_ptr->ready_mask = mask; }