public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] gdbserver/linux-low: use std::list to store pending signals
Date: Sat, 20 Jun 2020 20:25:54 +0100	[thread overview]
Message-ID: <eeba4770-4060-66f4-f882-c11b7c37cd0b@redhat.com> (raw)
In-Reply-To: <1592568732-3668-1-git-send-email-tankut.baris.aktemur@intel.com>

LGTM with a few nits below.

On 6/19/20 1:12 PM, Tankut Baris Aktemur via Gdb-patches wrote:

> @@ -2144,32 +2132,24 @@ enqueue_one_deferred_signal (struct lwp_info *lwp, int *wstat)
>       twice)  */
>    if (WSTOPSIG (*wstat) < __SIGRTMIN)
>      {
> -      struct pending_signals *sig;
> -
> -      for (sig = lwp->pending_signals_to_report;
> -	   sig != NULL;
> -	   sig = sig->prev)
> +      for (auto &sig : lwp->pending_signals_to_report)

const auto ?

> -  p_sig = XCNEW (struct pending_signals);
> -  p_sig->prev = lwp->pending_signals_to_report;
> -  p_sig->signal = WSTOPSIG (*wstat);
> +  lwp->pending_signals_to_report.emplace_back (WSTOPSIG (*wstat));
>  
>    ptrace (PTRACE_GETSIGINFO, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0,
> -	  &p_sig->info);
> -
> -  lwp->pending_signals_to_report = p_sig;
> +	  &(lwp->pending_signals_to_report.back ().info));

Redundant parens.

>  }
>  
>  /* Dequeue one signal from the "signals to report later when out of
> @@ -2180,20 +2160,16 @@ dequeue_one_deferred_signal (struct lwp_info *lwp, int *wstat)
>  {
>    struct thread_info *thread = get_lwp_thread (lwp);
>  
> -  if (lwp->pending_signals_to_report != NULL)
> +  if (!lwp->pending_signals_to_report.empty ())
>      {
> -      struct pending_signals **p_sig;
> +      const pending_signal &p_sig = lwp->pending_signals_to_report.front ();
>  
> -      p_sig = &lwp->pending_signals_to_report;
> -      while ((*p_sig)->prev != NULL)
> -	p_sig = &(*p_sig)->prev;
> -
> -      *wstat = W_STOPCODE ((*p_sig)->signal);
> -      if ((*p_sig)->info.si_signo != 0)
> +      *wstat = W_STOPCODE (p_sig.signal);
> +      if (p_sig.info.si_signo != 0)
>  	ptrace (PTRACE_SETSIGINFO, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0,
> -		&(*p_sig)->info);
> -      free (*p_sig);
> -      *p_sig = NULL;
> +		&(p_sig.info));

Redundant parens.

> +
> +      lwp->pending_signals_to_report.pop_front ();
>  
>        if (debug_threads)
>  	debug_printf ("Reporting deferred signal %d for LWP %ld.\n",
> @@ -2201,13 +2177,9 @@ dequeue_one_deferred_signal (struct lwp_info *lwp, int *wstat)
>  
>        if (debug_threads)
>  	{
> -	  struct pending_signals *sig;
> -
> -	  for (sig = lwp->pending_signals_to_report;
> -	       sig != NULL;
> -	       sig = sig->prev)
> +	  for (auto &sig : lwp->pending_signals_to_report)

const ?

>  	    debug_printf ("   Still queued %d\n",
> -			  sig->signal);
> +			  sig.signal);
>  
>  	  debug_printf ("   (no more queued signals)\n");
>  	}
> @@ -4050,15 +4022,9 @@ linux_process_target::stop_all_lwps (int suspend, lwp_info *except)
>  static void
>  enqueue_pending_signal (struct lwp_info *lwp, int signal, siginfo_t *info)
>  {
> -  struct pending_signals *p_sig = XNEW (struct pending_signals);
> -
> -  p_sig->prev = lwp->pending_signals;
> -  p_sig->signal = signal;
> -  if (info == NULL)
> -    memset (&p_sig->info, 0, sizeof (siginfo_t));
> -  else
> -    memcpy (&p_sig->info, info, sizeof (siginfo_t));
> -  lwp->pending_signals = p_sig;
> +  lwp->pending_signals.emplace_back (signal);
> +  if (info != nullptr)
> +    lwp->pending_signals.back ().info = *info;

I noticed that the pending_signal ctor always initializes the
info field.  Seems wasteful when we're practically always going to
overwrite it.   How about not initializing it in the ctor,
and then here do the memset if info == NULL, as before?

Thanks,
Pedro Alves


  reply	other threads:[~2020-06-20 19:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 12:12 Tankut Baris Aktemur
2020-06-20 19:25 ` Pedro Alves [this message]
2020-06-22  8:54   ` Aktemur, Tankut Baris

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=eeba4770-4060-66f4-f882-c11b7c37cd0b@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tankut.baris.aktemur@intel.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).