From d2708b0f73d5f0e0a40b36da21c6a0d15405e739 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 5 Jan 2018 16:33:13 +0100 Subject: Task scheduler: Get rid of extended version of parallel range callback Wrap all arguments into TLS type of argument. Avoids some branching and also makes it easier to extend things in the future. --- source/blender/blenlib/BLI_task.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib/BLI_task.h') diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h index ccfa2b6e2e7..acfdd3729c1 100644 --- a/source/blender/blenlib/BLI_task.h +++ b/source/blender/blenlib/BLI_task.h @@ -116,15 +116,27 @@ void BLI_task_pool_delayed_push_begin(TaskPool *pool, int thread_id); void BLI_task_pool_delayed_push_end(TaskPool *pool, int thread_id); /* Parallel for routines */ -typedef void (*TaskParallelRangeFunc)(void *userdata, const int iter); -typedef void (*TaskParallelRangeFuncEx)(void *userdata, void *userdata_chunk, const int iter, const int thread_id); + +/* Per-thread specific data passed to the callback. */ +typedef struct ParallelRangeTLS { + /* Identifier of the thread who this data belongs to. */ + int thread_id; + /* Copy of user-specifier chunk, which is copied from original chunk to all + * worker threads. This is similar to OpenMP's firstprivate. + */ + void *userdata_chunk; +} ParallelRangeTLS; + +typedef void (*TaskParallelRangeFunc)(void *userdata, + const int iter, + const ParallelRangeTLS *tls); typedef void (*TaskParallelRangeFuncFinalize)(void *userdata, void *userdata_chunk); void BLI_task_parallel_range_ex( int start, int stop, void *userdata, void *userdata_chunk, const size_t userdata_chunk_size, - TaskParallelRangeFuncEx func_ex, + TaskParallelRangeFunc func, const bool use_threading, const bool use_dynamic_scheduling); void BLI_task_parallel_range( @@ -138,7 +150,7 @@ void BLI_task_parallel_range_finalize( void *userdata, void *userdata_chunk, const size_t userdata_chunk_size, - TaskParallelRangeFuncEx func_ex, + TaskParallelRangeFunc func, TaskParallelRangeFuncFinalize func_finalize, const bool use_threading, const bool use_dynamic_scheduling); -- cgit v1.2.3