This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Remove use of queue from remote.c
- From: Simon Marchi <simark at simark dot ca>
- To: Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Sun, 10 Jun 2018 18:05:31 -0400
- Subject: Re: [RFA] Remove use of queue from remote.c
- References: <20180607135423.6763-1-tom@tromey.com>
LGTM. Since you're touching that code, I would just suggest to use the "new"
ptid methods instead of the functions, as noted below.
On 2018-06-07 09:54 AM, Tom Tromey wrote:
> @@ -7144,34 +7062,15 @@ remote_target::discard_pending_stop_replies (struct inferior *inf)
> rns->pending_event[notif_client_stop.id] = NULL;
> }
>
> - param.remote = this;
> - param.input = inf;
> - param.output = NULL;
> /* Discard the stop replies we have already pulled with
> vStopped. */
> - QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
> - remove_stop_reply_for_inferior, ¶m);
> -}
> -
> -/* If its remote state is equal to the given remote state,
> - remove EVENT from the stop reply queue. */
> -
> -static int
> -remove_stop_reply_of_remote_state (QUEUE (stop_reply_p) *q,
> - QUEUE_ITER (stop_reply_p) *iter,
> - stop_reply_p event,
> - void *data)
> -{
> - struct queue_iter_param *param = (struct queue_iter_param *) data;
> - struct remote_state *rs = (struct remote_state *) param->input;
> -
> - if (event->rs == rs)
> - {
> - stop_reply_xfree (event);
> - QUEUE_remove_elem (stop_reply_p, q, iter);
> - }
> -
> - return 1;
> + auto iter = std::remove_if (rs->stop_reply_queue.begin (),
> + rs->stop_reply_queue.end (),
> + [=] (const stop_reply_up &event)
> + {
> + return ptid_get_pid (event->ptid) == inf->pid;
event->ptid.pid ()
> @@ -7218,20 +7097,29 @@ remote_notif_remove_once_on_match (QUEUE (stop_reply_p) *q,
> struct stop_reply *
> remote_target::remote_notif_remove_queued_reply (ptid_t ptid)
> {
> - struct queue_iter_param param;
> + remote_state *rs = get_remote_state ();
>
> - param.remote = this;
> - param.input = &ptid;
> - param.output = NULL;
> + auto iter = std::find_if (rs->stop_reply_queue.begin (),
> + rs->stop_reply_queue.end (),
> + [=] (const stop_reply_up &event)
> + {
> + return ptid_match (event->ptid, ptid);
event->ptid.matches (ptid)
> @@ -7262,38 +7150,28 @@ void
> remote_target::push_stop_reply (struct stop_reply *new_event)
> {
> remote_state *rs = get_remote_state ();
> - QUEUE_enque (stop_reply_p, rs->stop_reply_queue, new_event);
> + rs->stop_reply_queue.push_back (stop_reply_up (new_event));
>
> if (notif_debug)
> fprintf_unfiltered (gdb_stdlog,
> "notif: push 'Stop' %s to queue %d\n",
> target_pid_to_str (new_event->ptid),
> - QUEUE_length (stop_reply_p,
> - rs->stop_reply_queue));
> + int (rs->stop_reply_queue.size ()));
>
> mark_async_event_handler (rs->remote_async_inferior_event_token);
> }
>
> -static int
> -stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p) *q,
> - QUEUE_ITER (stop_reply_p) *iter,
> - struct stop_reply *event,
> - void *data)
> -{
> - ptid_t *ptid = (ptid_t *) data;
> -
> - return !(ptid_equal (*ptid, event->ptid)
> - && event->ws.kind == TARGET_WAITKIND_STOPPED);
> -}
> -
> /* Returns true if we have a stop reply for PTID. */
>
> int
> remote_target::peek_stop_reply (ptid_t ptid)
> {
> remote_state *rs = get_remote_state ();
> - return !QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
> - stop_reply_match_ptid_and_ws, &ptid);
> + for (auto &event : rs->stop_reply_queue)
> + if (ptid_equal (ptid, event->ptid)
ptid == event->ptid
> @@ -9850,11 +9701,16 @@ remote_target::kill_new_fork_children (int pid)
> /* Check for any pending fork events (not reported or processed yet)
> in process PID and kill those fork child threads as well. */
> remote_notif_get_pending_events (notif);
> - param.remote = this;
> - param.input = &pid;
> - param.output = NULL;
> - QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
> - remote_kill_child_of_pending_fork, ¶m);
> + for (auto &event : rs->stop_reply_queue)
> + if (is_pending_fork_parent (&event->ws, pid, event->ptid))
> + {
> + int child_pid = ptid_get_pid (event->ws.value.related_pid);
event->ws.value.related_pid.pid ()
Simon