Fix race condition between GC thread and
the teardown of RS.  The RS context was going away while
the objects were being deleted within the finializer.

Add more debugging for playCoreCommands.

Change-Id: I391f0b4db948f43f54017b47b062ab47d6a1ef64
diff --git a/rsLocklessFifo.cpp b/rsLocklessFifo.cpp
index 804c767..eb2af1c 100644
--- a/rsLocklessFifo.cpp
+++ b/rsLocklessFifo.cpp
@@ -210,3 +210,19 @@
 void LocklessCommandFifo::dumpState(const char *s) const {
     LOGV("%s %p  put %p, get %p,  buf %p,  end %p", s, this, mPut, mGet, mBuffer, mEnd);
 }
+
+void LocklessCommandFifo::printDebugData() const {
+    dumpState("printing fifo debug");
+    const uint32_t *pptr = (const uint32_t *)mGet;
+    pptr -= 8 * 4;
+    if (mGet < mBuffer) {
+        pptr = (const uint32_t *)mBuffer;
+    }
+
+
+    for (int ct=0; ct < 16; ct++) {
+        LOGV("fifo %p = 0x%08x  0x%08x  0x%08x  0x%08x", pptr, pptr[0], pptr[1], pptr[2], pptr[3]);
+        pptr += 4;
+    }
+
+}
diff --git a/rsLocklessFifo.h b/rsLocklessFifo.h
index c963963..eabdc3e 100644
--- a/rsLocklessFifo.h
+++ b/rsLocklessFifo.h
@@ -35,6 +35,8 @@
     bool init(uint32_t size);
     void shutdown();
 
+    void printDebugData() const;
+
     LocklessCommandFifo();
     ~LocklessCommandFifo();
 
diff --git a/rsThreadIO.cpp b/rsThreadIO.cpp
index 001ac55..6cf07de 100644
--- a/rsThreadIO.cpp
+++ b/rsThreadIO.cpp
@@ -56,6 +56,7 @@
         if (cmdID >= (sizeof(gPlaybackFuncs) / sizeof(void *))) {
             rsAssert(cmdID < (sizeof(gPlaybackFuncs) / sizeof(void *)));
             LOGE("playCoreCommands error con %p, cmd %i", con, cmdID);
+            mToCore.printDebugData();
         }
         gPlaybackFuncs[cmdID](con, data);
         mToCore.next();