Fix the RS frame timeout.
Previous a slow app would block from receiving new
commands until the timer expired.  This change will
expire the timer immediatly.

Change-Id: I42b949d21f98ee0f1d3156763cd723c3e9cabb67
diff --git a/rsContext.cpp b/rsContext.cpp
index 6a30b17..bffe3c0 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -245,20 +245,32 @@
 
     rsc->mRunning = true;
     bool mDraw = true;
+    bool doWait = true;
+
+    uint64_t targetTime = rsc->getTime();
     while (!rsc->mExit) {
-        mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw);
+        uint64_t waitTime = 0;
+        uint64_t now = rsc->getTime();
+        if (now < targetTime) {
+            waitTime = targetTime - now;
+        } else {
+            doWait = false;
+        }
+
+        mDraw |= rsc->mIO.playCoreCommands(rsc, doWait, waitTime);
         mDraw &= (rsc->mRootScript.get() != NULL);
         mDraw &= rsc->mHasSurface;
 
-        uint32_t targetTime = 0;
         if (mDraw && rsc->mIsGraphicsContext) {
-            targetTime = rsc->runRootScript();
+            uint64_t delay = rsc->runRootScript() * 1000000;
+            targetTime = rsc->getTime() + delay;
+            doWait = delay != 0;
 
             if (rsc->props.mLogVisual) {
                 rsc->displayDebugStats();
             }
 
-            mDraw = targetTime && !rsc->mPaused;
+            mDraw = !rsc->mPaused;
             rsc->timerSet(RS_TIMER_CLEAR_SWAP);
             rsc->mHal.funcs.swap(rsc);
             rsc->timerFrame();
@@ -266,12 +278,6 @@
             rsc->timerPrint();
             rsc->timerReset();
         }
-        if (targetTime > 1) {
-            int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000;
-            if (t > 0) {
-                usleep(t);
-            }
-        }
     }
 
     LOGV("%p, RS Thread exiting", rsc);