summaryrefslogtreecommitdiff
path: root/core/LocApiBase.h
diff options
context:
space:
mode:
authorKevin Tang <zhikait@codeaurora.org>2019-08-15 15:43:03 -0700
committerKevin Tang <zhikait@codeaurora.org>2019-08-16 11:20:03 -0700
commit32e36b84e103862364a8a037272156b2b3814b6f (patch)
tree3ad8bec2c0f1c1927162525a96d831151836571e /core/LocApiBase.h
parente549c9be3b4719dfa2aa5fbc64684c2b358e4213 (diff)
downloadgps-32e36b84e103862364a8a037272156b2b3814b6f.tar.gz
delete of shared LocApiBase::mMsgTask may cause issues
mMsgTask is static, its delete would impact other LocApi objects which don't know it is deleted. Added refcount to manage this shared obj. Change-Id: Iea81039b9cd74081c5230d6bb18ea80c2ee05916 CRs-Fixed: 2505569
Diffstat (limited to 'core/LocApiBase.h')
-rw-r--r--core/LocApiBase.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/LocApiBase.h b/core/LocApiBase.h
index 8c885f7..6dac585 100644
--- a/core/LocApiBase.h
+++ b/core/LocApiBase.h
@@ -34,6 +34,7 @@
#include <gps_extended.h>
#include <LocationAPI.h>
#include <MsgTask.h>
+#include <LocSharedLock.h>
#include <log_util.h>
namespace loc_core {
@@ -107,6 +108,7 @@ class LocApiBase {
friend struct LocKillMsg;
friend class ContextBase;
static MsgTask* mMsgTask;
+ static volatile int32_t mMsgTaskRefCount;
LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
protected:
@@ -121,7 +123,8 @@ protected:
LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
ContextBase* context = NULL);
inline virtual ~LocApiBase() {
- if (nullptr != mMsgTask) {
+ android_atomic_dec(&mMsgTaskRefCount);
+ if (nullptr != mMsgTask && 0 == mMsgTaskRefCount) {
mMsgTask->destroy();
mMsgTask = nullptr;
}
@@ -132,7 +135,9 @@ protected:
public:
inline void sendMsg(const LocMsg* msg) const {
- mMsgTask->sendMsg(msg);
+ if (nullptr != mMsgTask) {
+ mMsgTask->sendMsg(msg);
+ }
}
inline void destroy() {
close();