summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-05-21 07:13:48 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-05-21 07:13:48 +0000
commitfc82ebc60a0998f247f71e5a7236a542ddbecbad (patch)
treed872039b76feff39dc9c3d0398c81304cfc867ca
parent31226f09f1933afe8133eead00bf6f2adb621f08 (diff)
parent60c72c0a4cec04c4a85255c6965d6493337b3c80 (diff)
downloadgps-oreo-release.tar.gz
Change-Id: I722f82f34ff6a2186195092f3b33b6fe01132e9d
-rw-r--r--msm8996/utils/LocSharedLock.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/msm8996/utils/LocSharedLock.h b/msm8996/utils/LocSharedLock.h
index 6b9e27f..7fe6237 100644
--- a/msm8996/utils/LocSharedLock.h
+++ b/msm8996/utils/LocSharedLock.h
@@ -30,6 +30,7 @@
#define __LOC_SHARED_LOCK__
#include <stddef.h>
+#include <cutils/atomic.h>
#include <pthread.h>
// This is a utility created for use cases such that there are more than
@@ -39,16 +40,16 @@
// this share lock's share() method has to be called, so that the obj
// can maintain an accurate client count.
class LocSharedLock {
- uint32_t mRef;
+ volatile int32_t mRef;
pthread_mutex_t mMutex;
inline ~LocSharedLock() { pthread_mutex_destroy(&mMutex); }
public:
// first client to create this LockSharedLock
inline LocSharedLock() : mRef(1) { pthread_mutex_init(&mMutex, NULL); }
// following client(s) are to *share()* this lock created by the first client
- inline LocSharedLock* share() { mRef++; return this; }
+ inline LocSharedLock* share() { android_atomic_inc(&mRef); return this; }
// whe a client no longer needs this shared lock, drop() shall be called.
- inline void drop() { if (0 == --mRef) delete this; }
+ inline void drop() { if (1 == android_atomic_dec(&mRef)) delete this; }
// locking the lock to enter critical section
inline void lock() { pthread_mutex_lock(&mMutex); }
// unlocking the lock to leave the critical section