checkpoint filmstrip, implemented TLS.
diff --git a/rsContext.cpp b/rsContext.cpp
index 2a5f65d..7c46c0e 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -23,6 +23,7 @@
 using namespace android::renderscript;
 
 Context * Context::gCon = NULL;
+pthread_key_t Context::gThreadTLSKey = 0;
 
 void Context::initEGL()
 {
@@ -120,6 +121,18 @@
 
      rsc->initEGL();
 
+     ScriptTLSStruct *tlsStruct = new ScriptTLSStruct;
+     if (!tlsStruct) {
+         LOGE("Error allocating tls storage");
+         return NULL;
+     }
+     tlsStruct->mContext = rsc;
+     tlsStruct->mScript = NULL;
+     int status = pthread_setspecific(rsc->gThreadTLSKey, tlsStruct);
+     if (status) {
+         LOGE("pthread_setspecific %i", status);
+     }
+
      rsc->mStateVertex.init(rsc, rsc->mWidth, rsc->mHeight);
      rsc->setVertex(NULL);
      rsc->mStateFragment.init(rsc, rsc->mWidth, rsc->mHeight);
@@ -162,6 +175,12 @@
     int status;
     pthread_attr_t threadAttr;
 
+    status = pthread_key_create(&gThreadTLSKey, NULL);
+    if (status) {
+        LOGE("Failed to init thread tls key.");
+        return;
+    }
+
     status = pthread_attr_init(&threadAttr);
     if (status) {
         LOGE("Failed to init thread attribute.");
@@ -195,6 +214,7 @@
 
     if (mDev) {
         mDev->removeContext(this);
+        pthread_key_delete(gThreadTLSKey);
     }
 }