public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdbsupport] Add sequential_for_each
@ 2022-07-14 15:01 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2022-07-14 15:01 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=18a5766d09c262878018af26ecbada38d7262b4d
commit 18a5766d09c262878018af26ecbada38d7262b4d
Author: Tom de Vries <tdevries@suse.de>
Date: Thu Jul 14 17:01:52 2022 +0200
[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.
Diff:
---
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 */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-14 15:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 15:01 [binutils-gdb] [gdbsupport] Add sequential_for_each Tom de Vries
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).