From 688858d3a807536d2bdcead7b50fc4d0496dab44 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 16 May 2016 17:15:18 +0200 Subject: BLI_task: Add new 'BLI_task_parallel_range_finalize()'. Together with the extended loop callback and userdata_chunk, this allows to perform cumulative tasks (like aggregation) in a lockfree way using local userdata_chunk to store temp data, and once all workers have finished, to merge those userdata_chunks in the finalize callback (from calling thread, so no need to lock here either). Note that this changes how userdata_chunk is handled (now fully from 'main' thread, which means a given worker thread will always get the same userdata_chunk, without being re-initialized anymore to init value at start of each iter chunk). --- source/blender/blenlib/BLI_task.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (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 c511ec432ee..967e0be6d0a 100644 --- a/source/blender/blenlib/BLI_task.h +++ b/source/blender/blenlib/BLI_task.h @@ -119,11 +119,13 @@ size_t BLI_task_pool_tasks_done(TaskPool *pool); /* 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); +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, + const size_t userdata_chunk_size, + TaskParallelRangeFuncEx func_ex, const bool use_threading, const bool use_dynamic_scheduling); void BLI_task_parallel_range( @@ -132,6 +134,16 @@ void BLI_task_parallel_range( TaskParallelRangeFunc func, const bool use_threading); +void BLI_task_parallel_range_finalize( + int start, int stop, + void *userdata, + void *userdata_chunk, + const size_t userdata_chunk_size, + TaskParallelRangeFuncEx func_ex, + TaskParallelRangeFuncFinalize func_finalize, + const bool use_threading, + const bool use_dynamic_scheduling); + typedef void (*TaskParallelListbaseFunc)(void *userdata, struct Link *iter, int index); -- cgit v1.2.3