public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [RFA] Remove use of queue from remote.c
Date: Sun, 10 Jun 2018 22:05:00 -0000	[thread overview]
Message-ID: <94acb1dc-3220-3eb2-c63e-e612dad28b49@simark.ca> (raw)
In-Reply-To: <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, &param);
> -}
> -
> -/* 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, &param);
> +  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

  reply	other threads:[~2018-06-10 22:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07 13:54 Tom Tromey
2018-06-10 22:05 ` Simon Marchi [this message]
2018-06-11  4:31   ` Tom Tromey
2018-06-12 22:58     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94acb1dc-3220-3eb2-c63e-e612dad28b49@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).