diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-09 07:10:22 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-09 07:10:22 +0400 |
commit | f171d0f29c1394795c0a1dea2cb5118859e9ccdc (patch) | |
tree | 7836b2214cafec9a04effc7de8560eda74bcc9db /intern/cycles/kernel/osl | |
parent | 1c3640997c225d9bcd6e7559863d69366edc16ee (diff) |
Fix #33125: cycles OSL crash with multiple render sessions running at the same time.
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/osl_globals.h | 5 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_shader.cpp | 23 |
2 files changed, 28 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/osl_globals.h b/intern/cycles/kernel/osl/osl_globals.h index 5d557ffcb07..80ced9dfd62 100644 --- a/intern/cycles/kernel/osl/osl_globals.h +++ b/intern/cycles/kernel/osl/osl_globals.h @@ -68,6 +68,11 @@ struct OSLGlobals { }; static tls_ptr(ThreadData, thread_data); + static thread_mutex thread_data_mutex; + static volatile int thread_data_users; + + void thread_data_init(); + void thread_data_free(); }; CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index 0c8de058b5b..abf7c041cb3 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -32,9 +32,32 @@ CCL_NAMESPACE_BEGIN tls_ptr(OSLGlobals::ThreadData, OSLGlobals::thread_data); +volatile int OSLGlobals::thread_data_users = 0; +thread_mutex OSLGlobals::thread_data_mutex; /* Threads */ +void OSLGlobals::thread_data_init() +{ + thread_scoped_lock thread_data_lock(thread_data_mutex); + + if(thread_data_users == 0) + tls_create(OSLGlobals::ThreadData, thread_data); + + thread_data_users++; +} + +void OSLGlobals::thread_data_free() +{ + /* thread local storage delete */ + thread_scoped_lock thread_data_lock(thread_data_mutex); + + thread_data_users--; + + if(thread_data_users == 0) + tls_delete(OSLGlobals::ThreadData, thread_data); +} + void OSLShader::thread_init(KernelGlobals *kg) { OSL::ShadingSystem *ss = kg->osl.ss; |