[Bf-blender-cvs] [feb090c] depsgraph_refactor: Depsgraph: Avoid having one global lock for all the graphs

Sergey Sharybin noreply at git.blender.org
Thu Dec 18 16:23:56 CET 2014


Commit: feb090c45baf5a98074cb5ff87ec353bc46d70ec
Author: Sergey Sharybin
Date:   Thu Dec 18 20:22:10 2014 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rBfeb090c45baf5a98074cb5ff87ec353bc46d70ec

Depsgraph: Avoid having one global lock for all the graphs

That's a bit crazy to have single global lock in the .cpp file which
could be easily coupled into Depsgraph structure so it would never
interfere if several threads traverses the graphs.

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

M	source/blender/blenkernel/intern/blender.c
M	source/blender/depsgraph/DEG_depsgraph.h
M	source/blender/depsgraph/intern/depsgraph.cpp
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_eval.cpp
M	source/blender/windowmanager/intern/wm_playanim.c
M	source/creator/creator.c
M	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

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

diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 3ac3af7..501ab42 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -121,7 +121,6 @@ void free_blender(void)
 	IMB_exit();
 	BKE_images_exit();
 	DAG_exit();
-	DEG_threaded_exit();
 	DEG_free_node_types();
 
 	BKE_brush_system_exit();
diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h
index 987315a..ee5ce89 100644
--- a/source/blender/depsgraph/DEG_depsgraph.h
+++ b/source/blender/depsgraph/DEG_depsgraph.h
@@ -139,16 +139,6 @@ void DEG_evaluate_on_framechange(struct EvaluationContext *eval_ctx,
 void DEG_evaluate_on_refresh(struct EvaluationContext *eval_ctx,
                              Depsgraph *graph);
 
-/* ----------------------------------------------- */
-
-/* Initialise threading lock - called during application startup */
-void DEG_threaded_init(void);
-
-/* Free threading lock - called during application shutdown */
-void DEG_threaded_exit(void);
-
-/* ************************************************ */
-
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/source/blender/depsgraph/intern/depsgraph.cpp b/source/blender/depsgraph/intern/depsgraph.cpp
index 6e7c0b4..1bb087b 100644
--- a/source/blender/depsgraph/intern/depsgraph.cpp
+++ b/source/blender/depsgraph/intern/depsgraph.cpp
@@ -45,6 +45,7 @@ extern "C" {
 Depsgraph::Depsgraph()
 {
 	this->root_node = NULL;
+	BLI_spin_init(&lock);
 }
 
 Depsgraph::~Depsgraph()
@@ -55,6 +56,7 @@ Depsgraph::~Depsgraph()
 	if (this->root_node != NULL) {
 		OBJECT_GUARDED_DELETE(this->root_node, RootDepsNode);
 	}
+	BLI_spin_end(&lock);
 }
 
 /* Query Conditions from RNA ----------------------- */
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 0cdabea..6503579 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -33,17 +33,14 @@
 #ifndef __DEPSGRAPH_H__
 #define __DEPSGRAPH_H__
 
-#include <vector>
-
 #include "MEM_guardedalloc.h"
+#include "BLI_threads.h"  /* for SpinLock */
 
 #include "depsgraph_types.h"
 
 #include "depsgraph_util_map.h"
 #include "depsgraph_util_set.h"
 
-using std::vector;
-
 struct PointerRNA;
 struct PropertyRNA;
 
@@ -55,7 +52,6 @@ struct SubgraphDepsNode;
 struct ComponentDepsNode;
 struct OperationDepsNode;
 
-
 /* ************************************* */
 /* Relationships Between Nodes */
 
@@ -146,7 +142,7 @@ struct Depsgraph {
 	                               OperationDepsNode *to,
 	                               eDepsRelation_Type type,
 	                               const string &description);
-								   
+
 	DepsRelation *add_new_relation(DepsNode *from,
 	                               DepsNode *to,
 	                               eDepsRelation_Type type,
@@ -192,6 +188,11 @@ struct Depsgraph {
 	/* All operation nodes, sorted in order of single-thread traversal order. */
 	OperationNodes operations;
 
+	/* Spin lock for threading-critical operations.
+	 * Mainly used by graph evaluation.
+	 */
+	SpinLock lock;
+
 	// XXX: additional stuff like eval contexts, mempools for allocating nodes from, etc.
 };
 
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cpp b/source/blender/depsgraph/intern/depsgraph_eval.cpp
index c9532ae..738be88 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cpp
@@ -86,24 +86,6 @@ void DEG_set_eval_mode(eDEG_EvalMode mode)
 	}
 }
 
-/* ************************************ */
-/* Multi-Threaded Evaluation Internals. */
-
-static SpinLock threaded_update_lock;
-
-/* Initialise threading lock - called during application startup. */
-void DEG_threaded_init(void)
-{
-	BLI_spin_init(&threaded_update_lock);
-}
-
-/* Free threading lock - called during application shutdown. */
-void DEG_threaded_exit(void)
-{
-	DepsgraphDebug::stats_free();
-	BLI_spin_end(&threaded_update_lock);
-}
-
 /* ********************** */
 /* Evaluation Entrypoints */
 
@@ -167,7 +149,7 @@ static void calculate_eval_priority(OperationDepsNode *node)
 
 static void schedule_graph(TaskPool *pool, EvaluationContext *eval_ctx, Depsgraph *graph)
 {
-	BLI_spin_lock(&threaded_update_lock);
+	BLI_spin_lock(&graph->lock);
 	for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin();
 	     it != graph->operations.end();
 	     ++it)
@@ -178,7 +160,7 @@ static void schedule_graph(TaskPool *pool, EvaluationContext *eval_ctx, Depsgrap
 			node->scheduled = true;
 		}
 	}
-	BLI_spin_unlock(&threaded_update_lock);
+	BLI_spin_unlock(&graph->lock);
 }
 
 void deg_schedule_children(TaskPool *pool, EvaluationContext *eval_ctx,
@@ -197,10 +179,10 @@ void deg_schedule_children(TaskPool *pool, EvaluationContext *eval_ctx,
 			atomic_sub_uint32(&child->num_links_pending, 1);
 
 			if (child->num_links_pending == 0) {
-				BLI_spin_lock(&threaded_update_lock);
+				BLI_spin_lock(&graph->lock);
 				bool need_schedule = !child->scheduled;
 				child->scheduled = true;
-				BLI_spin_unlock(&threaded_update_lock);
+				BLI_spin_unlock(&graph->lock);
 
 				if (need_schedule) {
 					BLI_task_pool_push(pool, DEG_task_run_func, child, false, TASK_PRIORITY_LOW);
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index 76e4cfe..304e95f 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -1261,7 +1261,6 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
 	IMB_exit();
 	BKE_images_exit();
 	DAG_exit();
-	DEG_threaded_exit();
 	DEG_free_node_types();
 
 	totblock = MEM_get_memory_blocks_in_use();
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 1ee8ae6..61b5057 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -1606,7 +1606,6 @@ int main(
 	/* after level 1 args, this is so playanim skips RNA init */
 	RNA_init();
 
-	DEG_threaded_init();
 	RE_engines_init();
 	init_nodesystem();
 	psys_init_rng();
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 5288a08..8e24e7d 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -456,7 +456,6 @@ int main(int argc, char** argv)
 	BKE_images_init();
 	BKE_modifier_init();
 	DAG_init();
-	DEG_threaded_init();
 	DEG_register_node_types();
 
 #ifdef WITH_FFMPEG
@@ -1136,7 +1135,6 @@ int main(int argc, char** argv)
 	IMB_exit();
 	BKE_images_exit();
 	DAG_exit();
-	DEG_threaded_exit();
 	DEG_free_node_types();
 	IMB_moviecache_destruct();




More information about the Bf-blender-cvs mailing list