[Bf-blender-cvs] [01581d4a1eb] blender2.8: BLI_task: fix queue in work_and_wait, and support resetting.

Alexander Gavrilov noreply at git.blender.org
Tue Dec 4 12:09:19 CET 2018


Commit: 01581d4a1eb595f2bb49d4b87aebfa8bd67ceb38
Author: Alexander Gavrilov
Date:   Mon Dec 3 22:55:18 2018 +0300
Branches: blender2.8
https://developer.blender.org/rB01581d4a1eb595f2bb49d4b87aebfa8bd67ceb38

BLI_task: fix queue in work_and_wait, and support resetting.

To make the pool more usable for running multiple stages of tasks,
fix local queue handling in BLI_task_pool_work_and_wait.

Specifically, after the wait loop the local queue should be empty,
or the wait part of the function contract isn't fulfilled. Instead,
check and run any tasks in queue before the wait loop.

Also, add a new function that resets the suspended state of the pool.

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

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

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

diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h
index 9194caca007..8300f6242db 100644
--- a/source/blender/blenlib/BLI_task.h
+++ b/source/blender/blenlib/BLI_task.h
@@ -98,6 +98,8 @@ void BLI_task_pool_push_from_thread(TaskPool *pool, TaskRunFunction run,
 
 /* work and wait until all tasks are done */
 void BLI_task_pool_work_and_wait(TaskPool *pool);
+/* work and wait until all tasks are done, then reset to the initial suspended state */
+void BLI_task_pool_work_wait_and_reset(TaskPool *pool);
 /* cancel all tasks, keep worker threads running */
 void BLI_task_pool_cancel(TaskPool *pool);
 
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index 047a7c0cc3b..edd588bd68b 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -175,6 +175,7 @@ struct TaskPool {
 	volatile bool do_work;
 
 	volatile bool is_suspended;
+	bool start_suspended;
 	ListBase suspended_queue;
 	size_t num_suspended;
 
@@ -650,6 +651,7 @@ static TaskPool *task_pool_create_ex(TaskScheduler *scheduler,
 	pool->do_cancel = false;
 	pool->do_work = false;
 	pool->is_suspended = is_suspended;
+	pool->start_suspended = is_suspended;
 	pool->num_suspended = 0;
 	pool->suspended_queue.first = pool->suspended_queue.last = NULL;
 	pool->run_in_background = is_background;
@@ -855,6 +857,8 @@ void BLI_task_pool_work_and_wait(TaskPool *pool)
 
 			BLI_condition_notify_all(&scheduler->queue_cond);
 			BLI_mutex_unlock(&scheduler->queue_mutex);
+
+			pool->num_suspended = 0;
 		}
 	}
 
@@ -862,6 +866,8 @@ void BLI_task_pool_work_and_wait(TaskPool *pool)
 
 	ASSERT_THREAD_ID(pool->scheduler, pool->thread_id);
 
+	handle_local_queue(tls, pool->thread_id);
+
 	BLI_mutex_lock(&pool->num_mutex);
 
 	while (pool->num != 0) {
@@ -913,7 +919,15 @@ void BLI_task_pool_work_and_wait(TaskPool *pool)
 
 	BLI_mutex_unlock(&pool->num_mutex);
 
-	handle_local_queue(tls, pool->thread_id);
+	BLI_assert(tls->num_local_queue == 0);
+}
+
+void BLI_task_pool_work_wait_and_reset(TaskPool *pool)
+{
+	BLI_task_pool_work_and_wait(pool);
+
+	pool->do_work = false;
+	pool->is_suspended = pool->start_suspended;
 }
 
 void BLI_task_pool_cancel(TaskPool *pool)



More information about the Bf-blender-cvs mailing list