From 32e36b84e103862364a8a037272156b2b3814b6f Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Thu, 15 Aug 2019 15:43:03 -0700 Subject: 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 --- core/LocApiBase.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'core/LocApiBase.h') 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 #include #include +#include #include 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(); -- cgit v1.2.3