Fix safe for mp check in ScriptC.

Change-Id: Id91b3c1e99b2705fd39f9e74a52c61110805e246
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 3681bc2..a7f380f 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -33,6 +33,8 @@
 #include <GLES2/gl2ext.h>
 
 #include <cutils/sched_policy.h>
+#include <sys/syscall.h>
+#include <string.h>
 
 using namespace android;
 using namespace android::renderscript;
@@ -371,11 +373,15 @@
      rsc->mWorkers.mLaunchSignals[idx].init();
      rsc->mWorkers.mNativeThreadId[idx] = gettid();
 
-     //cpu_set_t cpset[16];
-     //int ret = sched_getaffinity(rsc->mWorkers.mNativeThreadId[idx], sizeof(cpset), &cpset);
-     //LOGE("ret = %i", ret);
-
-//sched_setaffinity
+#if 0
+     typedef struct {uint64_t bits[1024 / 64]; } cpu_set_t;
+     cpu_set_t cpuset;
+     memset(&cpuset, 0, sizeof(cpuset));
+     cpuset.bits[idx / 64] |= 1ULL << (idx % 64);
+     int ret = syscall(241, rsc->mWorkers.mNativeThreadId[idx],
+		       sizeof(cpuset), &cpuset);
+     LOGE("SETAFFINITY ret = %i %s", ret, EGLUtils::strerror(ret));
+#endif
 
      setpriority(PRIO_PROCESS, rsc->mWorkers.mNativeThreadId[idx], rsc->mThreadPriority);
      while(rsc->mRunning) {
@@ -490,6 +496,7 @@
         usleep(100);
     }
 
+    mWorkers.mCompleteSignal.init();
     mWorkers.mRunningCount = 0;
     mWorkers.mLaunchCount = 0;
     for (uint32_t ct=0; ct < mWorkers.mCount; ct++) {
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index bce9c13..b85d2a8 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -174,7 +174,7 @@
     uint32_t getMaxVertexUniformVectors() const {return mGL.mMaxVertexUniformVectors;}
 
     void launchThreads(WorkerCallback_t cbk, void *data);
-    uint32_t getWorkerPoolSize() const {return (uint32_t)mWorkers.mRunningCount;}
+    uint32_t getWorkerPoolSize() const {return (uint32_t)mWorkers.mCount;}
 
 protected:
     Device *mDev;
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index f905492..e9621b9 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -201,7 +201,7 @@
         }
 
         //LOGE("usr idx %i, x %i,%i  y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd);
-
+        //LOGE("usr ptr in %p,  out %p", mtls->ptrIn, mtls->ptrOut);
         for (uint32_t y = yStart; y < yEnd; y++) {
             uint32_t offset = mtls->dimX * y;
             uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset);
@@ -296,14 +296,12 @@
         mtls.eStrideOut = aout->getType()->getElementSizeBytes();
     }
 
-
-    if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable &&
-        ((mtls.dimY * mtls.dimZ * mtls.dimArray) > 1)) {
+    if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable && (mtls.dimY > 1)) {
 
         //LOGE("launch 1");
         rsc->launchThreads(wc_xy, &mtls);
-        //LOGE("launch 2");
     } else {
+        //LOGE("launch 3");
         for (uint32_t ar = mtls.arrayStart; ar < mtls.arrayEnd; ar++) {
             for (uint32_t z = mtls.zStart; z < mtls.zEnd; z++) {
                 for (uint32_t y = mtls.yStart; y < mtls.yEnd; y++) {
@@ -380,11 +378,11 @@
     if (sym) {
         return sym->mPtr;
     }
-    s->mEnviroment.mIsThreadable = false;
     sym = ScriptCState::lookupSymbolCL(name);
     if (sym) {
         return sym->mPtr;
     }
+    s->mEnviroment.mIsThreadable = false;
     sym = ScriptCState::lookupSymbolGL(name);
     if (sym) {
         return sym->mPtr;