[Bf-blender-cvs] [90e1602] depsgraph_refactor: Depsgraph: Use spin lock in DepsgraphDebug

Sergey Sharybin noreply at git.blender.org
Mon Jan 5 18:07:11 CET 2015


Commit: 90e16022bd924f5063078ede17a6978d88ee0022
Author: Sergey Sharybin
Date:   Mon Jan 5 22:04:11 2015 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rB90e16022bd924f5063078ede17a6978d88ee0022

Depsgraph: Use spin lock in DepsgraphDebug

Amount of oepration was really small so using mutex was a total overkill.

On the other hand, this code didn't really run on normal scene update
(which i understood after doing the changes..) so it's not like you can
expect any visible changes from this. More like "nice to have".

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

M	source/blender/depsgraph/intern/depsgraph_debug.cpp
M	source/blender/depsgraph/intern/depsgraph_debug.h
M	source/blender/depsgraph/intern/depsgraph_eval.cpp

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

diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cpp b/source/blender/depsgraph/intern/depsgraph_debug.cpp
index 807d00e..5abeb99 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cpp
@@ -51,9 +51,11 @@ extern "C" {
 #include "depsgraph_types.h"
 #include "depsgraph_intern.h"
 
-/* ************************************************ */
+/* ****************** */
 /* Graphviz Debugging */
 
+static SpinLock lock;
+
 #define NL "\r\n"
 
 static const char *deg_debug_graphviz_fontname = "helvetica";
@@ -771,10 +773,11 @@ void DepsgraphDebug::eval_step(const EvaluationContext *eval_ctx,
 #endif
 }
 
-void DepsgraphDebug::task_started(const OperationDepsNode *node)
+void DepsgraphDebug::task_started(Depsgraph *graph,
+                                  const OperationDepsNode *node)
 {
 	if (stats) {
-		BLI_mutex_lock(&stats_mutex);
+		BLI_spin_lock(&graph->lock);
 
 		ComponentDepsNode *comp = node->owner;
 		ID *id = comp->owner->id;
@@ -789,14 +792,16 @@ void DepsgraphDebug::task_started(const OperationDepsNode *node)
 			times_clear(comp_stats->times);
 		}
 
-		BLI_mutex_unlock(&stats_mutex);
+		BLI_spin_unlock(&graph->lock);
 	}
 }
 
-void DepsgraphDebug::task_completed(const OperationDepsNode *node, double time)
+void DepsgraphDebug::task_completed(Depsgraph *graph,
+                                    const OperationDepsNode *node,
+                                    double time)
 {
 	if (stats) {
-		BLI_mutex_lock(&stats_mutex);
+		BLI_spin_lock(&graph->lock);
 
 		ComponentDepsNode *comp = node->owner;
 		ID *id = comp->owner->id;
@@ -811,15 +816,14 @@ void DepsgraphDebug::task_completed(const OperationDepsNode *node, double time)
 			times_add(comp_stats->times, time);
 		}
 
-		BLI_mutex_unlock(&stats_mutex);
+		BLI_spin_unlock(&graph->lock);
 	}
 }
 
-/* ************************************************ */
+/* ********** */
 /* Statistics */
 
 DepsgraphStats *DepsgraphDebug::stats = NULL;
-ThreadMutex DepsgraphDebug::stats_mutex;
 
 /* GHash callback */
 static void deg_id_stats_free(void *val)
@@ -837,16 +841,12 @@ void DepsgraphDebug::stats_init()
 	if (!stats) {
 		stats = (DepsgraphStats *)MEM_callocN(sizeof(DepsgraphStats), "Depsgraph Stats");
 		stats->id_stats = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "Depsgraph ID Stats Hash");
-
-		BLI_mutex_init(&stats_mutex);
 	}
 }
 
 void DepsgraphDebug::stats_free()
 {
 	if (stats) {
-		BLI_mutex_end(&stats_mutex);
-
 		BLI_ghash_free(stats->id_stats, NULL, deg_id_stats_free);
 		MEM_freeN(stats);
 		stats = NULL;
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.h b/source/blender/depsgraph/intern/depsgraph_debug.h
index c95aa90..9878ff6 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.h
+++ b/source/blender/depsgraph/intern/depsgraph_debug.h
@@ -27,10 +27,6 @@
 #ifndef __DEPSGRAPH_DEBUG_H__
 #define __DEPSGRAPH_DEBUG_H__
 
-extern "C" {
-#include "BLI_threads.h"
-}
-
 #include "depsgraph_types.h"
 
 struct DepsgraphStats;
@@ -56,8 +52,10 @@ struct DepsgraphDebug {
 	static void eval_step(const EvaluationContext *eval_ctx,
 	                      const char *message);
 
-	static void task_started(const OperationDepsNode *node);
-	static void task_completed(const OperationDepsNode *node, double time);
+	static void task_started(Depsgraph *graph, const OperationDepsNode *node);
+	static void task_completed(Depsgraph *graph,
+	                           const OperationDepsNode *node,
+	                           double time);
 
 	static DepsgraphStatsID *get_id_stats(ID *id, bool create);
 	static DepsgraphStatsComponent *get_component_stats(DepsgraphStatsID *id_stats,
@@ -69,9 +67,6 @@ struct DepsgraphDebug {
 	{
 		return get_component_stats(get_id_stats(id, create), name, create);
 	}
-
-protected:
-	static ThreadMutex stats_mutex;
 };
 
 #endif  /* __DEPSGRAPH_DEBUG_H__ */
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cpp b/source/blender/depsgraph/intern/depsgraph_eval.cpp
index 81533e6..80c0a66 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cpp
@@ -137,7 +137,7 @@ static void deg_task_run_func(TaskPool *pool,
 
 		/* Take note of current time. */
 		double start_time = PIL_check_seconds_timer();
-		DepsgraphDebug::task_started(node);
+		DepsgraphDebug::task_started(state->graph, node);
 
 		/* Should only be the case for NOOPs, which never get to this point. */
 		BLI_assert(node->evaluate != NULL);
@@ -147,7 +147,9 @@ static void deg_task_run_func(TaskPool *pool,
 
 		/* Note how long this took. */
 		double end_time = PIL_check_seconds_timer();
-		DepsgraphDebug::task_completed(node, end_time - start_time);
+		DepsgraphDebug::task_completed(state->graph,
+		                               node,
+		                               end_time - start_time);
 	}
 
 	schedule_children(pool, state->eval_ctx, state->graph, node, state->layers);




More information about the Bf-blender-cvs mailing list