From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 9ABEB3838788 for ; Sat, 25 Jun 2022 13:20:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9ABEB3838788 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CD5751F982 for ; Sat, 25 Jun 2022 13:20:45 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B24B813456 for ; Sat, 25 Jun 2022 13:20:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id e/tlKq0Lt2JyIwAAMHmgww (envelope-from ) for ; Sat, 25 Jun 2022 13:20:45 +0000 Date: Sat, 25 Jun 2022 15:20:44 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdbsupport] Add sequential_for_each Message-ID: <20220625132042.GA31575@delia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2022 13:20:47 -0000 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? Thanks, - Tom [gdbsupport] Add sequential_for_each --- gdbsupport/parallel-for.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index 7b6891a0dcb..16bca4fe3cf 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -172,6 +172,25 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last, }); } +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 */