From 1b555c0e3cb7a783926107454cab530843f622a0 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <gonnet@google.com> Date: Tue, 11 Feb 2020 12:52:25 +0000 Subject: [PATCH] Use a named value `threadpool_auto_chunk_size` instead of just passing zero to `threadpool_map`. --- src/threadpool.c | 8 +++----- src/threadpool.h | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index 0ef69f9895..9a29faab65 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -252,7 +252,7 @@ void threadpool_init(struct threadpool *tp, int num_threads) { * @param N Number of elements in @c map_data. * @param stride Size, in bytes, of each element of @c map_data. * @param chunk Number of map data elements to pass to the function at a time, - * or zero to choose the number automatically. + * or #threadpool_auto_chunk_size to choose the number automatically. * @param extra_data Addtitional pointer that will be passed to the mapping * function, may contain additional data. */ @@ -278,10 +278,8 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, tp->map_data_stride = stride; tp->map_data_size = N; tp->map_data_count = 0; - tp->map_data_chunk = - chunk ? chunk - : max((int)(N / (tp->num_threads * threadpool_default_chunk_ratio)), - 1); + tp->map_data_chunk = (chunk == threadpool_auto_chunk_size) ? + max((int)(N / (tp->num_threads * threadpool_default_chunk_ratio)), 1) : chunk; tp->map_function = map_function; tp->map_data = map_data; tp->map_extra_data = extra_data; diff --git a/src/threadpool.h b/src/threadpool.h index 9d19b56836..a4964ffcbb 100644 --- a/src/threadpool.h +++ b/src/threadpool.h @@ -32,6 +32,7 @@ /* Local defines. */ #define threadpool_log_initial_size 1000 #define threadpool_default_chunk_ratio 7 +#define threadpool_auto_chunk_size 0 /* Function type for mappings. */ typedef void (*threadpool_map_function)(void *map_data, int num_elements, -- GitLab