[4/8] gdbserver/linux: take condition out of callback in find_lwp_pid

Message ID 20221117194241.1776125-5-simon.marchi@efficios.com
State Committed
Commit d4895ba2df3bbf38d64fce314f5933d05eb8990a
Headers
Series Fix some commit_resumed_state assertion failures (PR 28275) |

Commit Message

Simon Marchi Nov. 17, 2022, 7:42 p.m. UTC
  Just a small optimization, it's not necessary to recompute lwp at each
iteration.

While at it, change the variable type to long, as ptid_t::lwp returns a
long.

Change-Id: I181670ce1f90b59cb09ea4899367750be2ad9105
---
 gdbserver/linux-low.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Andrew Burgess Nov. 18, 2022, 11:28 a.m. UTC | #1
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> Just a small optimization, it's not necessary to recompute lwp at each
> iteration.
>
> While at it, change the variable type to long, as ptid_t::lwp returns a
> long.
>
> Change-Id: I181670ce1f90b59cb09ea4899367750be2ad9105

LGTM.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

> ---
>  gdbserver/linux-low.cc | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
> index 0cbfeb99086..a896b37528b 100644
> --- a/gdbserver/linux-low.cc
> +++ b/gdbserver/linux-low.cc
> @@ -1731,9 +1731,9 @@ linux_process_target::status_pending_p_callback (thread_info *thread,
>  struct lwp_info *
>  find_lwp_pid (ptid_t ptid)
>  {
> -  thread_info *thread = find_thread ([&] (thread_info *thr_arg)
> +  long lwp = ptid.lwp () != 0 ? ptid.lwp () : ptid.pid ();
> +  thread_info *thread = find_thread ([lwp] (thread_info *thr_arg)
>      {
> -      int lwp = ptid.lwp () != 0 ? ptid.lwp () : ptid.pid ();
>        return thr_arg->id.lwp () == lwp;
>      });
>  
> -- 
> 2.37.3
  
Simon Marchi Nov. 18, 2022, 4:09 p.m. UTC | #2
On 11/18/22 06:28, Andrew Burgess via Gdb-patches wrote:
> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> Just a small optimization, it's not necessary to recompute lwp at each
>> iteration.
>>
>> While at it, change the variable type to long, as ptid_t::lwp returns a
>> long.
>>
>> Change-Id: I181670ce1f90b59cb09ea4899367750be2ad9105
> 
> LGTM.
> 
> Reviewed-By: Andrew Burgess <aburgess@redhat.com>

Thanks, I pushed this patch.

Simon
  

Patch

diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 0cbfeb99086..a896b37528b 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -1731,9 +1731,9 @@  linux_process_target::status_pending_p_callback (thread_info *thread,
 struct lwp_info *
 find_lwp_pid (ptid_t ptid)
 {
-  thread_info *thread = find_thread ([&] (thread_info *thr_arg)
+  long lwp = ptid.lwp () != 0 ? ptid.lwp () : ptid.pid ();
+  thread_info *thread = find_thread ([lwp] (thread_info *thr_arg)
     {
-      int lwp = ptid.lwp () != 0 ? ptid.lwp () : ptid.pid ();
       return thr_arg->id.lwp () == lwp;
     });