[Bf-blender-cvs] [7b4cc0f] depsgraph_refactor: Cleanup: Use generic task scheduler instead of own one

Sergey Sharybin noreply at git.blender.org
Mon Oct 13 15:10:00 CEST 2014


Commit: 7b4cc0fc5783904287eb6e0c3442b56173e9a3ca
Author: Sergey Sharybin
Date:   Mon Oct 13 15:08:34 2014 +0200
Branches: depsgraph_refactor
https://developer.blender.org/rB7b4cc0fc5783904287eb6e0c3442b56173e9a3ca

Cleanup: Use generic task scheduler instead of own one

helps to get rid of some of the utility structures which only adds
extra complexity to the code.

Let's keep new depsgraph as clean and small as possible! :)

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

M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/depsgraph_debug.cpp
M	source/blender/depsgraph/intern/depsgraph_debug.h
M	source/blender/depsgraph/intern/depsgraph_eval.cpp
M	source/blender/depsgraph/intern/depsgraph_eval.h
D	source/blender/depsgraph/util/depsgraph_util_priority_queue.h
M	source/blender/depsgraph/util/depsgraph_util_task.cpp
M	source/blender/depsgraph/util/depsgraph_util_task.h
D	source/blender/depsgraph/util/depsgraph_util_thread.h

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

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index a0d533d..db1bbeb 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -76,13 +76,11 @@ set(SRC
 	util/depsgraph_util_hash.h
 	util/depsgraph_util_id.h
 	util/depsgraph_util_map.h
-	util/depsgraph_util_priority_queue.h
 	util/depsgraph_util_rna.h
 	util/depsgraph_util_set.h
 	util/depsgraph_util_string.h
 	util/depsgraph_util_task.h
 	util/depsgraph_util_task.cpp
-	util/depsgraph_util_thread.h
 	util/depsgraph_util_type_traits.h
 )
 
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cpp b/source/blender/depsgraph/intern/depsgraph_debug.cpp
index 8b044da..143d701 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cpp
@@ -740,12 +740,11 @@ void DepsgraphDebug::eval_step(eEvaluationContextType context_type, const char *
 #endif
 }
 
-void DepsgraphDebug::task_started(const DepsgraphTask &task)
+void DepsgraphDebug::task_started(const OperationDepsNode *node)
 {
 	if (stats) {
 		BLI_mutex_lock(&stats_mutex);
 		
-		OperationDepsNode *node = task.node;
 		ComponentDepsNode *comp = node->owner;
 		ID *id = comp->owner->id;
 		
@@ -763,12 +762,11 @@ void DepsgraphDebug::task_started(const DepsgraphTask &task)
 	}
 }
 
-void DepsgraphDebug::task_completed(const DepsgraphTask &task, double time)
+void DepsgraphDebug::task_completed(const OperationDepsNode *node, double time)
 {
 	if (stats) {
 		BLI_mutex_lock(&stats_mutex);
 		
-		OperationDepsNode *node = task.node;
 		ComponentDepsNode *comp = node->owner;
 		ID *id = comp->owner->id;
 		
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.h b/source/blender/depsgraph/intern/depsgraph_debug.h
index 6f9c974..3afdc5e 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.h
+++ b/source/blender/depsgraph/intern/depsgraph_debug.h
@@ -35,21 +35,21 @@
 
 extern "C" {
 #include "DNA_userdef_types.h"
+#include "BLI_threads.h"
 }
 
 #include "DEG_depsgraph_debug.h"
 #include "DEG_depsgraph.h"
 
 #include "depsgraph_util_string.h"
-#include "depsgraph_util_thread.h"
 
 struct DepsgraphStats;
 struct DepsgraphStatsID;
 struct DepsgraphStatsComponent;
 struct DepsgraphSettings;
+struct OperationDepsNode;
 
 struct Depsgraph;
-struct DepsgraphTask;
 
 struct DepsgraphDebug {
 	static DepsgraphStats *stats;
@@ -64,8 +64,8 @@ struct DepsgraphDebug {
 	static void eval_end(eEvaluationContextType context_type);
 	static void eval_step(eEvaluationContextType context_type, const char *message);
 	
-	static void task_started(const DepsgraphTask &task);
-	static void task_completed(const DepsgraphTask &task, double time);
+	static void task_started(const OperationDepsNode *node);
+	static void task_completed(const OperationDepsNode *node, double time);
 	
 	static DepsgraphStatsID *get_id_stats(ID *id, bool create);
 	static DepsgraphStatsComponent *get_component_stats(DepsgraphStatsID *id_stats, const string &name, bool create);
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cpp b/source/blender/depsgraph/intern/depsgraph_eval.cpp
index c3d90fc..249f52f 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cpp
@@ -35,6 +35,7 @@
 extern "C" {
 #include "BLI_blenlib.h"
 #include "BLI_string.h"
+#include "BLI_task.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
@@ -95,7 +96,6 @@ static SpinLock threaded_update_lock;
 /* Initialise threading lock - called during application startup */
 void DEG_threaded_init(void)
 {
-	DepsgraphTaskScheduler::init();
 	BLI_spin_init(&threaded_update_lock);
 }
 
@@ -104,7 +104,6 @@ void DEG_threaded_exit(void)
 {
 	DepsgraphDebug::stats_free();
 	
-	DepsgraphTaskScheduler::exit();
 	BLI_spin_end(&threaded_update_lock);
 }
 
@@ -154,21 +153,21 @@ static void calculate_eval_priority(OperationDepsNode *node)
 		node->eval_priority = 0.0f;
 }
 
-static void schedule_graph(DepsgraphTaskPool &pool, Depsgraph *graph, eEvaluationContextType context_type)
+static void schedule_graph(TaskPool *pool, Depsgraph *graph, eEvaluationContextType context_type)
 {
 	BLI_spin_lock(&threaded_update_lock);
 	for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin(); it != graph->operations.end(); ++it) {
 		OperationDepsNode *node = *it;
 		
 		if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) && node->num_links_pending == 0) {
-			pool.push(graph, node, context_type);
+			BLI_task_pool_push(pool, DEG_task_run_func, node, false, TASK_PRIORITY_LOW);
 			node->scheduled = true;
 		}
 	}
 	BLI_spin_unlock(&threaded_update_lock);
 }
 
-void deg_schedule_children(DepsgraphTaskPool &pool, Depsgraph *graph, eEvaluationContextType context_type, OperationDepsNode *node)
+void deg_schedule_children(TaskPool *pool, Depsgraph *graph, eEvaluationContextType context_type, OperationDepsNode *node)
 {
 	for (OperationDepsNode::Relations::const_iterator it = node->outlinks.begin(); it != node->outlinks.end(); ++it) {
 		DepsRelation *rel = *it;
@@ -184,8 +183,9 @@ void deg_schedule_children(DepsgraphTaskPool &pool, Depsgraph *graph, eEvaluatio
 				child->scheduled = true;
 				BLI_spin_unlock(&threaded_update_lock);
 				
-				if (need_schedule)
-					pool.push(graph, child, context_type);
+				if (need_schedule) {
+					BLI_task_pool_push(pool, DEG_task_run_func, child, false, TASK_PRIORITY_LOW);
+				}
 			}
 		}
 	}
@@ -202,7 +202,12 @@ void DEG_evaluate_on_refresh(Depsgraph *graph, eEvaluationContextType context_ty
 	// TODO: this needs both main and scene access...
 	
 	/* XXX could use a separate pool for each eval context */
-	static DepsgraphTaskPool task_pool = DepsgraphTaskPool();
+	DepsgraphEvalState state;
+	state.graph = graph;
+	state.context_type = context_type;
+
+	TaskScheduler *task_scheduler = BLI_task_scheduler_get();
+	TaskPool *task_pool = BLI_task_pool_create(task_scheduler, &state);
 	
 	/* recursively push updates out to all nodes dependent on this, 
 	 * until all affected are tagged and/or scheduled up for eval
@@ -226,7 +231,8 @@ void DEG_evaluate_on_refresh(Depsgraph *graph, eEvaluationContextType context_ty
 	
 	schedule_graph(task_pool, graph, context_type);
 	
-	task_pool.wait();
+	BLI_task_pool_work_and_wait(task_pool);
+	BLI_task_pool_free(task_pool);
 	
 	DepsgraphDebug::eval_end(context_type);
 	
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.h b/source/blender/depsgraph/intern/depsgraph_eval.h
index 5523d35..9f4be5d 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.h
+++ b/source/blender/depsgraph/intern/depsgraph_eval.h
@@ -134,10 +134,9 @@ typedef struct DEG_PoseContext {
 
 /* ****************************************** */
 
-struct DepsgraphTaskPool;
 struct Depsgraph;
 struct OperationDepsNode;
-
-void deg_schedule_children(DepsgraphTaskPool &pool, Depsgraph *graph, eEvaluationContextType context_type, OperationDepsNode *node);
+struct Taskpool;
+void deg_schedule_children(TaskPool *pool, Depsgraph *graph, eEvaluationContextType context_type, OperationDepsNode *node);
 
 #endif // __DEPSGRAPH_EVAL_TYPES_H__
diff --git a/source/blender/depsgraph/util/depsgraph_util_priority_queue.h b/source/blender/depsgraph/util/depsgraph_util_priority_queue.h
deleted file mode 100644
index 3c50a14..0000000
--- a/source/blender/depsgraph/util/depsgraph_util_priority_queue.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2014 Blender Foundation.
- * All rights reserved.
- *
- * Original Author: Lukas Toenne
- * Contributor(s): 
- */
-
-#ifndef __DEPSGRAPH_UTIL_PRIORITY_QUEUE_H__
-#define __DEPSGRAPH_UTIL_PRIORITY_QUEUE_H__
-
-#include <queue>
-#include <vector>
-
-using std::priority_queue;
-using std::vector;
-
-#endif /* __DEPSGRAPH_UTIL_PRIORITY_QUEUE_H__ */
diff --git a/source/blender/depsgraph/util/depsgraph_util_task.cpp b/source/blender/depsgraph/util/depsgraph_util_task.cpp
index 8d0380d..24594eb 100644
--- a/source/blender/depsgraph/util/depsgraph_util_task.cpp
+++ b/source/blender/depsgraph/util/depsgraph_util_task.cpp
@@ -31,11 +31,11 @@
 
 extern "C" {
 #include "BLI_rand.h" /* XXX for eval simulation only, remove eventually */
+#include "BLI_task.h"
 }
 
 #include "depsgraph_debug.h"
 #include "depsgraph_eval.h"
-#include "depsnode_component.h"
 
 #include "depsgraph_util_task.h"
 
@@ -56,32 +56,29 @@ static void deg_eval_sim_free()
 }
 /* ******** */
 
-DepsgraphTask::DepsgraphTask(Depsgraph *graph_, OperationDepsNode *node_, eEvaluationContextType context_type_) :
-    graph(graph_),
-    node(node_),
-    context_type(context_type_)
+void DEG_task_run_func(TaskPool *pool, void *taskdata, int UNUSED(threadid))
 {
-}
-
-void DepsgraphTask::run()
-{
-	if (node->is_noop())
+	DepsgraphEvalState *state = (DepsgraphEvalState *)BLI_task_pool_userdata(pool);
+	OperationDepsNode *node = (OperationDepsNode *)taskdata;
+	if (node->is_noop()) {
+		deg_schedule_children(pool, state->graph, state->context_type, node);
 		return;
-	
+	}
+
 	/* get context */
 	// TODO: who initialises this? "Init" operations aren't able to initialise it!!!
-	ComponentDepsNode *comp = node->owner; 
+	ComponentDepsNode *comp = node->owner;
 	BLI_assert(comp != NULL);
-	
+
 	/* take note of current time */
 	double start_time = PIL_check_seconds_timer();
-	DepsgraphDebug::task_started(*this);
-	
+	DepsgraphDebug::task_started(node);
+
 	if (DEG_get_eval_mode() == DEG_EVAL

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list