diff options
author | Martin Poirier <theeth@yahoo.com> | 2009-09-03 00:57:18 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2009-09-03 00:57:18 +0400 |
commit | 9004dc665cd303dc6bc84d1ea92716dc0c0020d3 (patch) | |
tree | 045732329fbc147123f79dec5567d08855d61566 /source | |
parent | 375f36dfcf21f046b2cde0a24a0846999e87d57a (diff) |
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).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 2812f17d58f..ed3e07b7f7e 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -142,10 +142,10 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) 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 @@ void BLI_end_threads(ListBase *threadbase) { 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) |