From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Remove for_each_thread
Date: Thu, 14 May 2026 10:13:31 -0400 [thread overview]
Message-ID: <9c0a15ea-df3d-4795-9028-f290fdeb8232@simark.ca> (raw)
In-Reply-To: <20260513-remove-for-each-v1-2-8793bd79f781@adacore.com>
On 2026-05-13 13:32, Tom Tromey wrote:
> This patch removes the for_each_thread function, changing the callers
> to use 'foreach' loops instead. In general I think loops with
> iterators should be preferred over callback-based approaches -- they
> are easier to read and often result in less source code as well. For
> example, in this patch a helper function is inlined into its sole
> caller.
Perhaps mention that there is a functional change, since you switch from
using all_threads_safe to all_threads everywhere. This happens to fix
the bug that Markus was fixing here:
https://inbox.sourceware.org/gdb-patches/20260504071636.1571615-2-markus.t.metzger@intel.com/
I would have liked to see a test along with that fix (I supplied one
down-thread), but whatever.
The other callers don't seem to need all_threads_safe, at first glance.
> @@ -607,16 +605,16 @@ print_one_inferior (struct inferior *inferior, bool recurse,
>
> if (inferior->pid != 0)
> {
> - for_each_thread ([&] (struct thread_info *ti)
> + for (auto &ti : all_threads ())
> {
> - if (ti->ptid.pid () == inferior->pid)
> + if (ti.ptid.pid () == inferior->pid)
> {
> - int core = target_core_of_thread (ti->ptid);
> + int core = target_core_of_thread (ti.ptid);
>
> if (core != -1)
> cores.insert (core);
> }
> - });
> + }
You could remove the braces of the "for" here.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
next prev parent reply other threads:[~2026-05-14 14:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 17:32 [PATCH 0/2] " Tom Tromey
2026-05-13 17:32 ` [PATCH 1/2] Use bool in continue_1 Tom Tromey
2026-05-14 14:00 ` Simon Marchi
2026-05-13 17:32 ` [PATCH 2/2] Remove for_each_thread Tom Tromey
2026-05-14 14:13 ` Simon Marchi [this message]
2026-05-14 17:48 ` Tom Tromey
2026-07-22 18:21 ` [PATCH 0/2] " 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=9c0a15ea-df3d-4795-9028-f290fdeb8232@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.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