]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbsupport: make gdb::parallel_for_each's n parameter a template parameter
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 5 May 2025 20:15:26 +0000 (16:15 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 13 Jun 2025 18:38:57 +0000 (14:38 -0400)
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
Approved-By: Tom Tromey <tom@tromey.com>
gdb/minsyms.c
gdb/unittests/parallel-for-selftests.c
gdbsupport/parallel-for.h

index 124d96d90b5627cfdaf27e5c76d7a39b7be770e2..4a6459a6f2d2f5543c511c4e01788a6e7b430b41 100644 (file)
@@ -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");
index c9a1689acfb0d21185cfb4ba43d18910db647761..f3d85a85704ccc07c2f8d19337906660fb677271 100644 (file)
@@ -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 })
index c485c36d48596b39f7f5ed13fc895dd3eb1428f4..b74c8068cf2c26b0b8d117dc45db780ce9094a96 100644 (file)
@@ -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);
 }