aboutsummaryrefslogtreecommitdiff
path: root/gps/utils/LocSharedLock.h
diff options
context:
space:
mode:
authorcrancocco <shulaibai@hustunique.com>2016-06-25 22:55:16 +0800
committerdavidevinavil <davidevinavil@gmail.com>2017-01-21 18:26:28 +0100
commitb80452111794b613819d5ad51e1690c4dd923e97 (patch)
treedf2b4d14fdd89a40f6e11a24d93949e7bebfd8e5 /gps/utils/LocSharedLock.h
parent8126cb8c09f99ae625364c98b1301d0c5390e27d (diff)
z2_plus: Update GPS HAL from upstream
* Tag LA.HB.1.3.2-15400-8x96.0 Change-Id: I2ba108f26a2ef4fc78504ef8c08ca41624ccb193
Diffstat (limited to 'gps/utils/LocSharedLock.h')
-rw-r--r--gps/utils/LocSharedLock.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/gps/utils/LocSharedLock.h b/gps/utils/LocSharedLock.h
index 6b9e27f..7fe6237 100644
--- a/gps/utils/LocSharedLock.h
+++ b/gps/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