Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2016-12-23 11:30:05 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-03-03 19:42:33 +0300
commit1ea1b04e549c755a153d506476c9e4759a2d5567 (patch)
treecaeb0b46154b238e3565d567f87f6f6c784269de
parent1659d42bf704db674adce621bb071d206eefe024 (diff)
Never starve main thread (run_and_wait) from tasks!
-rw-r--r--source/blender/blenlib/intern/task.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index eebe7f12589..fd14b7becd3 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -273,7 +273,8 @@ static void task_pool_num_increase(TaskPool *pool)
}
}
-BLI_INLINE bool task_find(TaskScheduler * restrict scheduler, Task ** restrict task, TaskPool * restrict pool)
+BLI_INLINE bool task_find(
+ TaskScheduler * restrict scheduler, Task ** restrict task, TaskPool * restrict pool, const bool is_main)
{
Task *current_task;
bool found_task = false;
@@ -296,12 +297,12 @@ BLI_INLINE bool task_find(TaskScheduler * restrict scheduler, Task ** restrict t
continue;
}
- if (scheduler->background_thread_only && !current_pool->run_in_background) {
+ if (!is_main && scheduler->background_thread_only && !current_pool->run_in_background) {
continue;
}
if (atomic_add_and_fetch_z(&current_pool->currently_running_tasks, 1) <= current_pool->num_threads ||
- current_pool->num_threads == 0)
+ is_main || current_pool->num_threads == 0)
{
*task = current_task;
found_task = true;
@@ -367,7 +368,7 @@ static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task
return false;
}
- if (!(found_task = task_find(scheduler, task, NULL))) {
+ if (!(found_task = task_find(scheduler, task, NULL, false))) {
if (task_wait(scheduler, &loop_count)) {
return false;
}
@@ -717,7 +718,7 @@ void BLI_task_pool_work_and_wait(TaskPool *pool)
/* find task from this pool. if we get a task from another pool,
* we can get into deadlock */
- found_task = task_find(scheduler, &task, pool);
+ found_task = task_find(scheduler, &task, pool, true);
/* if found task, do it, otherwise wait until other tasks are done */
if (found_task) {