[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57938] branches/soc-2013-depsgraph_mt/ source/blender/blenkernel/intern/scene.c: Replace mutex lock with spinlock in threaded object update

Sergey Sharybin sergey.vfx at gmail.com
Tue Jul 2 21:22:52 CEST 2013


Revision: 57938
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57938
Author:   nazgul
Date:     2013-07-02 19:22:52 +0000 (Tue, 02 Jul 2013)
Log Message:
-----------
Replace mutex lock with spinlock in threaded object update

It's not so much happening inside the lock and using spin
lock instead of mutex lock will give some speedup due to
smaller latency of resuming the thread when mutex was locked.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c	2013-07-02 19:22:49 UTC (rev 57937)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c	2013-07-02 19:22:52 UTC (rev 57938)
@@ -1169,6 +1169,7 @@
 typedef struct ThreadedObjectUpdateState {
 	Scene *scene;
 	Scene *scene_parent;
+	SpinLock lock;
 } ThreadedObjectUpdateState;
 
 static void scene_update_object_add_task(void *node, void *user_data);
@@ -1221,10 +1222,10 @@
 		        DAG_threaded_update_get_node_name(node));
 	}
 
-	BLI_lock_thread(LOCK_CUSTOM1);
+	BLI_spin_lock(&state->lock);
 	/* Update will decrease child's valency and schedule child with zero valency. */
 	DAG_threaded_update_handle_node_updated(node,scene_update_object_add_task, pool);
-	BLI_unlock_thread(LOCK_CUSTOM1);
+	BLI_spin_unlock(&state->lock);
 
 #undef PRINT
 }
@@ -1280,6 +1281,7 @@
 
 	state.scene = scene;
 	state.scene_parent = scene_parent;
+	BLI_spin_init(&state.lock);
 
 	task_scheduler = BLI_task_scheduler_create(tot_thread);
 	task_pool = BLI_task_pool_create(task_scheduler, &state);
@@ -1307,6 +1309,8 @@
 	BLI_task_scheduler_free(task_scheduler);
 
 	BLI_end_threaded_malloc();
+
+	BLI_spin_end(&state.lock);
 }
 
 static void scene_update_objects(Scene *scene, Scene *scene_parent)




More information about the Bf-blender-cvs mailing list