[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22956] branches/blender2.5/blender/source /blender/blenlib/intern/threads.c: Fix thread hanging problem ( mostly seen with material preview, but that sneaky f*er could strike any time).
Martin Poirier
theeth at yahoo.com
Wed Sep 2 22:57:18 CEST 2009
Revision: 22956
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22956
Author: theeth
Date: 2009-09-02 22:57:18 +0200 (Wed, 02 Sep 2009)
Log Message:
-----------
Fix thread hanging problem (mostly seen with material preview, but that sneaky f*er could strike any time).
Story time: Once upon a time, in the green valley of fileselect, BLI_end_threads would get called on an empty threadbase, depending on the result of a previous call to readdir(). The function would then gladly decrement thread_level to -1 which would cause all kinds of fun havoc. THE END.
Made sure thread_level is only incremented and decremented when needed. The caller should never have to make sure of that, especially since it already lets you call with a null threadbase.
Please report any further hang (and how to reproduce, if possible).
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenlib/intern/threads.c
Modified: branches/blender2.5/blender/source/blender/blenlib/intern/threads.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/threads.c 2009-09-02 20:54:33 UTC (rev 22955)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/threads.c 2009-09-02 20:57:18 UTC (rev 22956)
@@ -142,10 +142,10 @@
tslot->do_thread= do_thread;
tslot->avail= 1;
}
+
+ MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
+ thread_levels++;
}
-
- MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
- thread_levels++;
}
/* amount of available threads */
@@ -235,18 +235,21 @@
{
ThreadSlot *tslot;
- if (threadbase) {
+ /* only needed if there's actually some stuff to end
+ * this way we don't end up decrementing thread_levels on an empty threadbase
+ * */
+ if (threadbase && threadbase->first != NULL) {
for(tslot= threadbase->first; tslot; tslot= tslot->next) {
if(tslot->avail==0) {
pthread_join(tslot->pthread, NULL);
}
}
BLI_freelistN(threadbase);
+
+ thread_levels--;
+ if(thread_levels==0)
+ MEM_set_lock_callback(NULL, NULL);
}
-
- thread_levels--;
- if(thread_levels==0)
- MEM_set_lock_callback(NULL, NULL);
}
void BLI_lock_thread(int type)
More information about the Bf-blender-cvs
mailing list