From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 065B53853540; Thu, 14 Jul 2022 15:01:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 065B53853540 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdbsupport] Add sequential_for_each X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: e24500cbab783d42656d3b745947c98d7d5bdd83 X-Git-Newrev: 18a5766d09c262878018af26ecbada38d7262b4d Message-Id: <20220714150156.065B53853540@sourceware.org> Date: Thu, 14 Jul 2022 15:01:56 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2022 15:01:56 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D18a5766d09c2= 62878018af26ecbada38d7262b4d commit 18a5766d09c262878018af26ecbada38d7262b4d Author: Tom de Vries Date: Thu Jul 14 17:01:52 2022 +0200 [gdbsupport] Add sequential_for_each =20 Add a sequential_for_each alongside the parallel_for_each, which can be= used as a drop-in replacement. =20 This can be useful when debugging multi-threading behaviour, and you wa= nt to limit multi-threading in a fine-grained way. =20 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, RandomI= t last, }); } =20 +/* A sequential drop-in replacement of parallel_for_each. This can be use= ful + 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 + =3D typename std::result_of::type; + + gdb::detail::par_for_accumulator results (0); + + /* Process all the remaining elements in the main thread. */ + return results.finish ([=3D] () + { + return callback (first, last); + }); +} + } =20 #endif /* GDBSUPPORT_PARALLEL_FOR_H */