Implement java interface for RS shutdown and fix shutdown deadlock with the command fifo.
diff --git a/rsContext.cpp b/rsContext.cpp
index c8c69a8..3ebfdce 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -243,11 +243,13 @@
          }
      }
 
+     LOGV("RS Thread exiting");
      glClearColor(0,0,0,0);
      glClear(GL_COLOR_BUFFER_BIT);
      eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
      eglTerminate(rsc->mEGL.mDisplay);
      rsc->objDestroyOOBRun();
+     LOGV("RS Thread exited");
      return NULL;
 }
 
@@ -298,9 +300,11 @@
 
 Context::~Context()
 {
+    LOGV("Context::~Context");
     mExit = true;
     void *res;
 
+    mIO.shutdown();
     int status = pthread_join(mThreadId, &res);
     objDestroyOOBRun();
 
diff --git a/rsLocklessFifo.cpp b/rsLocklessFifo.cpp
index c3fee54..0c40389 100644
--- a/rsLocklessFifo.cpp
+++ b/rsLocklessFifo.cpp
@@ -25,6 +25,16 @@
 
 LocklessCommandFifo::~LocklessCommandFifo()
 {
+    if (!mInShutdown) {
+        shutdown();
+    }
+    free(mBuffer);
+}
+
+void LocklessCommandFifo::shutdown()
+{
+    mInShutdown = true;
+    mSignalToWorker.set();
 }
 
 bool LocklessCommandFifo::init(uint32_t sizeInBytes)
@@ -42,6 +52,7 @@
         return false;
     }
 
+    mInShutdown = false;
     mSize = sizeInBytes;
     mPut = mBuffer;
     mGet = mBuffer;
@@ -50,7 +61,7 @@
     return true;
 }
 
-uint32_t LocklessCommandFifo::getFreeSpace() const 
+uint32_t LocklessCommandFifo::getFreeSpace() const
 {
     int32_t freeSpace = 0;
     //dumpState("getFreeSpace");
@@ -115,7 +126,7 @@
 {
     while(1) {
         //dumpState("get");
-        while(isEmpty()) {
+        while(isEmpty() && !mInShutdown) {
             mSignalToControl.set();
             mSignalToWorker.wait();
         }
@@ -126,7 +137,7 @@
             // non-zero command is valid
             return mGet+4;
         }
-    
+
         // zero command means reset to beginning.
         mGet = mBuffer;
     }
@@ -161,7 +172,7 @@
     while(getFreeSpace() < bytes) {
         sleep(1);
     }
-    
+
 }
 
 void LocklessCommandFifo::dumpState(const char *s) const
diff --git a/rsLocklessFifo.h b/rsLocklessFifo.h
index abeddf7..d0a4356 100644
--- a/rsLocklessFifo.h
+++ b/rsLocklessFifo.h
@@ -25,13 +25,14 @@
 
 // A simple FIFO to be used as a producer / consumer between two
 // threads.  One is writer and one is reader.  The common cases
-// will not require locking.  It is not threadsafe for multiple 
+// will not require locking.  It is not threadsafe for multiple
 // readers or writers by design.
 
-class LocklessCommandFifo 
+class LocklessCommandFifo
 {
 public:
     bool init(uint32_t size);
+    void shutdown();
 
     LocklessCommandFifo();
     ~LocklessCommandFifo();
@@ -59,6 +60,7 @@
     uint8_t * mBuffer;
     uint8_t * mEnd;
     uint8_t mSize;
+    bool mInShutdown;
 
     Signal mSignalToWorker;
     Signal mSignalToControl;
diff --git a/rsThreadIO.cpp b/rsThreadIO.cpp
index 4a1dbbb..db4bb81 100644
--- a/rsThreadIO.cpp
+++ b/rsThreadIO.cpp
@@ -30,6 +30,11 @@
 {
 }
 
+void ThreadIO::shutdown()
+{
+    mToCore.shutdown();
+}
+
 bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand)
 {
     bool ret = false;
diff --git a/rsThreadIO.h b/rsThreadIO.h
index 4aab1b4..1f6a0c2 100644
--- a/rsThreadIO.h
+++ b/rsThreadIO.h
@@ -31,6 +31,8 @@
     ThreadIO();
     ~ThreadIO();
 
+    void shutdown();
+
     // Plays back commands from the client.
     // Returns true if any commands were processed.
     bool playCoreCommands(Context *con, bool waitForCommand);