[Bf-blender-cvs] [633fee72d5c] master: Fix T76427: edit mesh undo hanges when building without TBB

Brecht Van Lommel noreply at git.blender.org
Sat May 9 17:18:06 CEST 2020


Commit: 633fee72d5cb4c1f3136781561a72deb301a44d7
Author: Brecht Van Lommel
Date:   Sat May 9 17:01:40 2020 +0200
Branches: master
https://developer.blender.org/rB633fee72d5cb4c1f3136781561a72deb301a44d7

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

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

M	source/blender/blenlib/BLI_task.h
M	source/blender/blenlib/intern/task_pool.cc

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

diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h
index 3ef693ac62a..64dfdc2ad25 100644
--- a/source/blender/blenlib/BLI_task.h
+++ b/source/blender/blenlib/BLI_task.h
@@ -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);
+
+/* 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);
-TaskPool *BLI_task_pool_create_background_serial(void *userdata, TaskPriority priority);
+
 void BLI_task_pool_free(TaskPool *pool);
 
 void BLI_task_pool_push(TaskPool *pool,
diff --git a/source/blender/blenlib/intern/task_pool.cc b/source/blender/blenlib/intern/task_pool.cc
index d8e90af551a..c4d60673492 100644
--- a/source/blender/blenlib/intern/task_pool.cc
+++ b/source/blender/blenlib/intern/task_pool.cc
@@ -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)



More information about the Bf-blender-cvs mailing list