From 996db8dace63c452e5828586415b0dc57cccb3db Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Tue, 6 Oct 2009 17:16:55 -0700 Subject: [PATCH] Fix tls crash on startup if more than one RS contexts are created in one process. --- libs/rs/rsContext.cpp | 13 +++++++++---- libs/rs/rsScriptC.cpp | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index a1e9e45335ff7..195ea6f1d7d5c 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -304,10 +304,15 @@ Context::Context(Device *dev, Surface *sur, bool useDepth) int status; pthread_attr_t threadAttr; - status = pthread_key_create(&gThreadTLSKey, NULL); - if (status) { - LOGE("Failed to init thread tls key."); - return; + if (!gThreadTLSKey) { + status = pthread_key_create(&gThreadTLSKey, NULL); + if (status) { + LOGE("Failed to init thread tls key."); + return; + } + } else { + // HACK: workaround gl hang on start + exit(-1); } status = pthread_attr_init(&threadAttr); diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index 20088da31c226..9da7766217b61 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -62,6 +62,7 @@ bool ScriptC::run(Context *rsc, uint32_t launchIndex) { Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); + rsAssert(tls); if (mEnviroment.mFragmentStore.get()) { rsc->setFragmentStore(mEnviroment.mFragmentStore.get());