Fix deadlock on RS teardown.

Change-Id: I34d2702b535e28e9519c7368fd8a942bfe0724bc
diff --git a/rsObjectBase.cpp b/rsObjectBase.cpp
index e4b07c4..46b1750 100644
--- a/rsObjectBase.cpp
+++ b/rsObjectBase.cpp
@@ -93,9 +93,8 @@
         if (mRSC && mRSC->props.mLogObjects) {
             dumpLOGV("checkDelete");
         }
-        delete this;
-
         unlockUserRef();
+        delete this;
         return true;
     }
     return false;
@@ -170,9 +169,7 @@
 
 void ObjectBase::remove() const
 {
-    // Should be within gObjectInitMutex lock
-    // lock will be from checkDelete a few levels up in the stack.
-
+    lockUserRef();
     //LOGV("calling remove  rsc %p", mRSC);
     if (!mRSC) {
         rsAssert(!mPrev);
@@ -191,12 +188,11 @@
     }
     mPrev = NULL;
     mNext = NULL;
+    unlockUserRef();
 }
 
 void ObjectBase::zeroAllUserRef(Context *rsc)
 {
-    lockUserRef();
-
     if (rsc->props.mLogObjects) {
         LOGV("Forcing release of all outstanding user refs.");
     }
@@ -219,8 +215,6 @@
         LOGV("Objects remaining.");
         dumpAll(rsc);
     }
-
-    unlockUserRef();
 }
 
 void ObjectBase::dumpAll(Context *rsc)