Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/6] gdbsupport: make gdb::parallel_for_each's n parameter a template parameter
Date: Mon,  5 May 2025 16:15:26 -0400	[thread overview]
Message-ID: <20250505201548.184917-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20250505201548.184917-1-simon.marchi@efficios.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

This value will likely never change at runtime, so we might as well make
it a template parameter.  This has the "advantage" of being able to
remove the unnecessary param from gdb::sequential_for_each.

Change-Id: Ia172ab8e08964e30d4e3378a95ccfa782abce674
---
 gdb/minsyms.c                          |  2 +-
 gdb/unittests/parallel-for-selftests.c |  4 ++--
 gdbsupport/parallel-for.h              | 10 ++++------
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 124d96d90b56..4a6459a6f2d2 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1479,7 +1479,7 @@ minimal_symbol_reader::install ()
 
       msymbols = m_objfile->per_bfd->msymbols.get ();
       /* Arbitrarily require at least 10 elements in a thread.  */
-      gdb::parallel_for_each (10, &msymbols[0], &msymbols[mcount],
+      gdb::parallel_for_each<10> (&msymbols[0], &msymbols[mcount],
 	 [&] (minimal_symbol *start, minimal_symbol *end)
 	 {
 	   scoped_time_it time_it ("minsyms install worker");
diff --git a/gdb/unittests/parallel-for-selftests.c b/gdb/unittests/parallel-for-selftests.c
index c9a1689acfb0..f3d85a85704c 100644
--- a/gdb/unittests/parallel-for-selftests.c
+++ b/gdb/unittests/parallel-for-selftests.c
@@ -94,9 +94,9 @@ test_parallel_for_each ()
   const std::vector<do_foreach_t> for_each_functions
     {
       [] (int start, int end, foreach_callback_t callback)
-      { gdb::parallel_for_each (1, start, end, callback); },
+      { gdb::parallel_for_each<1> (start, end, callback); },
       [] (int start, int end, foreach_callback_t callback)
-      { gdb::sequential_for_each (1, start, end, callback);}
+      { gdb::sequential_for_each (start, end, callback);}
     };
 
   for (int n_threads : { 0, 1, 3 })
diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h
index c485c36d4859..b74c8068cf2c 100644
--- a/gdbsupport/parallel-for.h
+++ b/gdbsupport/parallel-for.h
@@ -40,10 +40,9 @@ namespace gdb
    at least N elements processed per thread.  Setting N to 0 is not
    allowed.  */
 
-template<class RandomIt, class RangeFunction>
+template<std::size_t n, class RandomIt, class RangeFunction>
 void
-parallel_for_each (unsigned n, RandomIt first, RandomIt last,
-		   RangeFunction callback)
+parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback)
 {
   /* If enabled, print debug info about how the work is distributed across
      the threads.  */
@@ -73,7 +72,7 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
   if (parallel_for_each_debug)
     {
       debug_printf (_("Parallel for: n_elements: %zu\n"), n_elements);
-      debug_printf (_("Parallel for: minimum elements per thread: %u\n"), n);
+      debug_printf (_("Parallel for: minimum elements per thread: %zu\n"), n);
       debug_printf (_("Parallel for: elts_per_thread: %zu\n"), elts_per_thread);
     }
 
@@ -141,8 +140,7 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
 
 template<class RandomIt, class RangeFunction>
 void
-sequential_for_each (unsigned n, RandomIt first, RandomIt last,
-		     RangeFunction callback)
+sequential_for_each (RandomIt first, RandomIt last, RangeFunction callback)
 {
   callback (first, last);
 }
-- 
2.49.0


  reply	other threads:[~2025-05-05 20:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 20:15 [PATCH 1/6] gdb: re-work parallel-for-selftests.c Simon Marchi
2025-05-05 20:15 ` Simon Marchi [this message]
2025-06-13 17:55   ` [PATCH 2/6] gdbsupport: make gdb::parallel_for_each's n parameter a template parameter Tom Tromey
2025-06-13 18:43     ` Simon Marchi
2025-05-05 20:15 ` [PATCH 3/6] gdbsupport: use dynamic partitioning in gdb::parallel_for_each Simon Marchi
2025-06-13 18:29   ` Tom Tromey
2025-06-13 19:22     ` Simon Marchi
2025-06-13 19:56       ` Simon Marchi
2025-06-13 20:12         ` Simon Marchi
2025-06-26 19:27           ` Simon Marchi
2025-07-03 19:23             ` Tom Tromey
2025-07-03 19:36               ` Simon Marchi
2025-05-05 20:15 ` [PATCH 4/6] gdbsupport: factor out work queue from parallel-for.h Simon Marchi
2025-06-13 18:33   ` Tom Tromey
2025-06-13 19:24     ` Simon Marchi
2025-05-05 20:15 ` [PATCH 5/6] gdbsupport: add async parallel_for_each version Simon Marchi
2025-06-13 18:39   ` Tom Tromey
2025-06-13 19:29     ` Simon Marchi
2025-05-05 20:15 ` [PATCH 6/6] gdb/dwarf: use dynamic partitioning for DWARF CU indexing Simon Marchi
2025-05-27 14:44 ` [PATCH 1/6] gdb: re-work parallel-for-selftests.c Simon Marchi
2025-06-13 17:48 ` Tom Tromey
2025-06-13 18:38   ` Simon Marchi

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=20250505201548.184917-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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