[Bf-blender-cvs] [d617de9] master: Fix (unreported) broken BLI_task's forloop func in case we have less iterations that workers.

Bastien Montagne noreply at git.blender.org
Mon Dec 28 00:40:03 CET 2015


Commit: d617de965ea20e5d563fa134b4910a67c4d8229d
Author: Bastien Montagne
Date:   Mon Dec 28 00:28:37 2015 +0100
Branches: master
https://developer.blender.org/rBd617de965ea20e5d563fa134b4910a67c4d8229d

Fix (unreported) broken BLI_task's forloop func in case we have less iterations that workers.

When called with very small range, `BLI_task_parallel_range_ex()` would generate a zero `chunk_size`,
leading to some infinite looping in `parallel_range_func` due to `parallel_range_next_iter_get` returning
true without actually increasing the counter!

So now, we ensure `chunk_size` and `num_tasks` are always at least 1 (and avoid generating too much tasks too).

===================================================================

M	source/blender/blenlib/intern/task.c

===================================================================

diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index 515da9c..104ebce 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -706,9 +706,11 @@ void BLI_task_parallel_range_ex(
 		state.chunk_size = 32;
 	}
 	else {
-		state.chunk_size = (stop - start) / (num_tasks);
+		state.chunk_size = max_ii(1, (stop - start) / (num_tasks));
 	}
 
+	num_tasks = max_ii(1, (stop - start) / state.chunk_size);
+
 	for (i = 0; i < num_tasks; i++) {
 		BLI_task_pool_push(task_pool,
 		                   parallel_range_func,




More information about the Bf-blender-cvs mailing list