From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [comitted][gdbsupport] Add sequential_for_each
Date: Thu, 14 Jul 2022 17:02:35 +0200 [thread overview]
Message-ID: <d3888f98-230b-f84c-23b3-69bdeeed828b@suse.de> (raw)
In-Reply-To: <20220625132042.GA31575@delia.com>
[-- Attachment #1: Type: text/plain, Size: 470 bytes --]
On 6/25/22 15:20, Tom de Vries wrote:
> Hi,
>
> Add a sequential_for_each alongside the parallel_for_each, which can be used
> as a drop-in replacement.
>
> This can be useful when debugging multi-threading behaviour, and you want to
> limit multi-threading in a fine-grained way.
>
> Tested on x86_64-linux, by using it instead of the parallel_for_each in
> dwarf2_build_psymtabs_hard.
>
> Any comments?
Added function header comment, and committed.
Thanks,
- Tom
[-- Attachment #2: 0001-gdbsupport-Add-sequential_for_each.patch --]
[-- Type: text/x-patch, Size: 1564 bytes --]
[gdbsupport] Add sequential_for_each
Add a sequential_for_each alongside the parallel_for_each, which can be used
as a drop-in replacement.
This can be useful when debugging multi-threading behaviour, and you want to
limit multi-threading in a fine-grained way.
Tested on x86_64-linux, by using it instead of the parallel_for_each in
dwarf2_build_psymtabs_hard.
---
gdbsupport/parallel-for.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h
index 7b6891a0dcb..a614fc35766 100644
--- a/gdbsupport/parallel-for.h
+++ b/gdbsupport/parallel-for.h
@@ -172,6 +172,29 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
});
}
+/* A sequential drop-in replacement of parallel_for_each. This can be useful
+ when debugging multi-threading behaviour, and you want to limit
+ multi-threading in a fine-grained way. */
+
+template<class RandomIt, class RangeFunction>
+typename gdb::detail::par_for_accumulator<
+ typename std::result_of<RangeFunction (RandomIt, RandomIt)>::type
+ >::result_type
+sequential_for_each (unsigned n, RandomIt first, RandomIt last,
+ RangeFunction callback)
+{
+ using result_type
+ = typename std::result_of<RangeFunction (RandomIt, RandomIt)>::type;
+
+ gdb::detail::par_for_accumulator<result_type> results (0);
+
+ /* Process all the remaining elements in the main thread. */
+ return results.finish ([=] ()
+ {
+ return callback (first, last);
+ });
+}
+
}
#endif /* GDBSUPPORT_PARALLEL_FOR_H */
next prev parent reply other threads:[~2022-07-14 15:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-25 13:20 [PATCH][gdbsupport] " Tom de Vries
2022-07-14 15:02 ` Tom de Vries [this message]
2022-07-15 16:38 ` Tom Tromey
2022-07-15 16:44 ` Tom de Vries
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=d3888f98-230b-f84c-23b3-69bdeeed828b@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/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).