From b859a3ef488cd1a3bf072f71002dced36353875b Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 5 Aug 2022 16:12:56 +0200 Subject: [gdbsupport] Add task size parameter in parallel_for_each Add a task_size parameter to parallel_for_each, defaulting to nullptr, and use the task size to distribute similarly-sized chunks to the threads. Tested on x86_64-linux. --- gdb/unittests/parallel-for-selftests.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gdb/unittests/parallel-for-selftests.c') diff --git a/gdb/unittests/parallel-for-selftests.c b/gdb/unittests/parallel-for-selftests.c index 8a86b43..6e341f6 100644 --- a/gdb/unittests/parallel-for-selftests.c +++ b/gdb/unittests/parallel-for-selftests.c @@ -68,6 +68,34 @@ test (int n_threads) }); SELF_CHECK (counter == 0); + auto task_size_max_ = [] (int iter) + { + return (size_t)SIZE_MAX; + }; + auto task_size_max = gdb::make_function_view (task_size_max_); + + counter = 0; + gdb::parallel_for_each (1, 0, NUMBER, + [&] (int start, int end) + { + counter += end - start; + }, task_size_max); + SELF_CHECK (counter == NUMBER); + + auto task_size_one_ = [] (int iter) + { + return (size_t)1; + }; + auto task_size_one = gdb::make_function_view (task_size_one_); + + counter = 0; + gdb::parallel_for_each (1, 0, NUMBER, + [&] (int start, int end) + { + counter += end - start; + }, task_size_one); + SELF_CHECK (counter == NUMBER); + #undef NUMBER } -- cgit v1.1