diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-03-08 11:41:38 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-03-08 11:41:38 +0300 |
commit | a095611eb87b5147e27da2b94463b0329c0a947e (patch) | |
tree | bd30a983d9a923d2a182cb334ff292bd48ecd5bc /source/blender/blenlib | |
parent | 3505be836114e4c0675ffe4e6740be1838f71a39 (diff) |
Fix T50886: Blender crashes on render
Was a mistake in one of the previous TLS commits.
See comment in the pool_create to see some details why it was crashing.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/task.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 49130fd4620..49d2ee83a66 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -55,15 +55,20 @@ #define LOCALQUEUE_SIZE 1 #ifndef NDEBUG -# define ASSERT_THREAD_ID(scheduler, thread_id) \ - do { \ - if (!BLI_thread_is_main()) { \ - TaskThread *thread = pthread_getspecific(scheduler->tls_id_key); \ - BLI_assert(thread_id == thread->id); \ - } \ - else { \ - BLI_assert(thread_id == 0); \ - } \ +# define ASSERT_THREAD_ID(scheduler, thread_id) \ + do { \ + if (!BLI_thread_is_main()) { \ + TaskThread *thread = pthread_getspecific(scheduler->tls_id_key); \ + if (thread == NULL) { \ + BLI_assert(thread_id == 0); \ + } \ + else { \ + BLI_assert(thread_id == thread->id); \ + } \ + } \ + else { \ + BLI_assert(thread_id == 0); \ + } \ } while (false) #else # define ASSERT_THREAD_ID(scheduler, thread_id) @@ -579,7 +584,17 @@ static TaskPool *task_pool_create_ex(TaskScheduler *scheduler, } else { TaskThread *thread = pthread_getspecific(scheduler->tls_id_key); - pool->thread_id = thread->id; + /* NOTE: It is possible that pool is created from non-main thread + * which isn't a scheduler thread. In this case pthread's TLS will + * be NULL and we can safely consider thread id 0 for the main + * thread of this pool (the one which does wort_and_wait()). + */ + if (thread == NULL) { + pool->thread_id = 0; + } + else { + pool->thread_id = thread->id; + } } #ifdef DEBUG_STATS |