mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
[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.
This commit is contained in:
@@ -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<class RandomIt, class RangeFunction>
|
||||||
|
typename gdb::detail::par_for_accumulator<
|
||||||
|
typename std::result_of<RangeFunction (RandomIt, RandomIt)>::type
|
||||||
|
>::result_type
|
||||||
|
sequential_for_each (unsigned n, RandomIt first, RandomIt last,
|
||||||
|
RangeFunction callback)
|
||||||
|
{
|
||||||
|
using result_type
|
||||||
|
= typename std::result_of<RangeFunction (RandomIt, RandomIt)>::type;
|
||||||
|
|
||||||
|
gdb::detail::par_for_accumulator<result_type> results (0);
|
||||||
|
|
||||||
|
/* Process all the remaining elements in the main thread. */
|
||||||
|
return results.finish ([=] ()
|
||||||
|
{
|
||||||
|
return callback (first, last);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GDBSUPPORT_PARALLEL_FOR_H */
|
#endif /* GDBSUPPORT_PARALLEL_FOR_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user