From: Tom de Vries Date: Thu, 14 Jul 2022 15:01:52 +0000 (+0200) Subject: [gdbsupport] Add sequential_for_each X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=18a5766d09c262878018af26ecbada38d7262b4d;p=binutils-gdb.git [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 --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 +typename gdb::detail::par_for_accumulator< + typename std::result_of::type + >::result_type +sequential_for_each (unsigned n, RandomIt first, RandomIt last, + RangeFunction callback) +{ + using result_type + = typename std::result_of::type; + + gdb::detail::par_for_accumulator results (0); + + /* Process all the remaining elements in the main thread. */ + return results.finish ([=] () + { + return callback (first, last); + }); +} + } #endif /* GDBSUPPORT_PARALLEL_FOR_H */