diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-12-28 02:28:37 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-12-28 02:37:07 +0300 |
commit | d617de965ea20e5d563fa134b4910a67c4d8229d (patch) | |
tree | b1383502d2d298ca31c4efe44d98771a81758419 /source | |
parent | 7ef10decdb609b6172f78a978b75454b3014b082 (diff) |
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).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/task.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 515da9cd95d..104ebcec26b 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, |