OSDN Git Service

Replace AppOpsManager locking with std::lock_guard
authorChristopher Wiley <wiley@google.com>
Fri, 12 Feb 2016 23:41:08 +0000 (15:41 -0800)
committerChristopher Wiley <wiley@google.com>
Fri, 12 Feb 2016 23:43:33 +0000 (15:43 -0800)
Change-Id: Ice4c101659837cea594194cfb335f9f3f6837f38

libs/binder/AppOpsManager.cpp

index 52cef1c..e97bde5 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <mutex>
 #include <binder/AppOpsManager.h>
 #include <binder/Binder.h>
 #include <binder/IServiceManager.h>
@@ -59,8 +60,8 @@ sp<IAppOpsService> AppOpsManager::getService() { return NULL; }
 sp<IAppOpsService> AppOpsManager::getService()
 {
 
+    std::lock_guard<Mutex> scoped_lock(mLock);
     int64_t startTime = 0;
-    mLock.lock();
     sp<IAppOpsService> service = mService;
     while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
         sp<IBinder> binder = defaultServiceManager()->checkService(_appops);
@@ -80,7 +81,6 @@ sp<IAppOpsService> AppOpsManager::getService()
             mService = service;
         }
     }
-    mLock.unlock();
     return service;
 }
 #endif  // defined(__BRILLO__)