Fix T76427: edit mesh undo hanges when building without TBB

Background task pools would not restart threads if reused multiple times,
thanks to Jeroen for identifying the cause of this problem.

Differential Revision: https://developer.blender.org/D7659
This commit is contained in:
Brecht Van Lommel 2020-05-09 17:01:40 +02:00
parent 9be28095cb
commit 633fee72d5
Notes: blender-bot 2023-02-14 02:58:19 +01:00
Referenced by issue #76427, Edit mesh undo-push hangs WITH_TBB=OFF
2 changed files with 24 additions and 5 deletions

View File

@ -49,7 +49,7 @@ int BLI_task_scheduler_num_threads(void);
/* Task Pool
*
* Pool of tasks that will be executed by the central TaskScheduler. For each
* Pool of tasks that will be executed by the central task scheduler. For each
* pool, we can wait for all tasks to be done, or cancel them before they are
* done.
*
@ -70,11 +70,27 @@ typedef struct TaskPool TaskPool;
typedef void (*TaskRunFunction)(TaskPool *__restrict pool, void *taskdata);
typedef void (*TaskFreeFunction)(TaskPool *__restrict pool, void *taskdata);
/* Regular task pool that immediately starts executing tasks as soon as they
* are pushed, either on the current or another thread. */
TaskPool *BLI_task_pool_create(void *userdata, TaskPriority priority);
/* Background: always run tasks in a background thread, never immediately
* execute them. For running background jobs. */
TaskPool *BLI_task_pool_create_background(void *userdata, TaskPriority priority);
TaskPool *BLI_task_pool_create_suspended(void *userdata, TaskPriority priority);
TaskPool *BLI_task_pool_create_no_threads(void *userdata);
/* Background Serial: run tasks one after the other in the background,
* without parallelization between the tasks. */
TaskPool *BLI_task_pool_create_background_serial(void *userdata, TaskPriority priority);
/* Suspended: don't execute tasks until work_and_wait is called. This is slower
* as threads can't immediately start working. But it can be used if the data
* structures the threads operate on are not fully initialized until all tasks
* are created. */
TaskPool *BLI_task_pool_create_suspended(void *userdata, TaskPriority priority);
/* No threads: immediately executes tasks on the same thread. For debugging. */
TaskPool *BLI_task_pool_create_no_threads(void *userdata);
void BLI_task_pool_free(TaskPool *pool);
void BLI_task_pool_push(TaskPool *pool,

View File

@ -305,7 +305,6 @@ static void background_task_pool_create(TaskPool *pool)
{
pool->background_queue = BLI_thread_queue_init();
BLI_threadpool_init(&pool->background_threads, background_task_run, 1);
BLI_threadpool_insert(&pool->background_threads, pool);
}
static void background_task_pool_run(TaskPool *pool, Task &&task)
@ -313,6 +312,10 @@ static void background_task_pool_run(TaskPool *pool, Task &&task)
Task *task_mem = (Task *)MEM_mallocN(sizeof(Task), __func__);
new (task_mem) Task(std::move(task));
BLI_thread_queue_push(pool->background_queue, task_mem);
if (BLI_available_threads(&pool->background_threads)) {
BLI_threadpool_insert(&pool->background_threads, pool);
}
}
static void background_task_pool_work_and_wait(TaskPool *pool)
@ -321,7 +324,7 @@ static void background_task_pool_work_and_wait(TaskPool *pool)
* left, and wait for tasks and thread to finish. */
BLI_thread_queue_nowait(pool->background_queue);
BLI_thread_queue_wait_finish(pool->background_queue);
BLI_threadpool_remove(&pool->background_threads, pool);
BLI_threadpool_clear(&pool->background_threads);
}
static void background_task_pool_cancel(TaskPool *pool)