summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Tang <zhikait@codeaurora.org>2018-07-23 16:24:00 -0700
committerKevin Tang <zhikait@codeaurora.org>2018-07-30 16:17:37 -0700
commita8f926020f4883aa3915b8e5e0d35e09527bbbd5 (patch)
tree116415be58b890d71b1055631f3b59ef50c4042e
parentaa6481f63899a072602191893c0b9e25fba758dc (diff)
downloadgps-a8f926020f4883aa3915b8e5e0d35e09527bbbd5.tar.gz
Delete LocApiBase and derived class on msgTask thread
Direct delete of the API obj on caller thread could result in a race condition that caller still has close() or other handling running at the same time the API object is being or already deleted. CRs-Fixed: 2275383 Change-Id: I5d3de204befec3c22c73cece8516e90800abbd35
-rw-r--r--core/ContextBase.h11
-rw-r--r--core/LocApiBase.h21
2 files changed, 29 insertions, 3 deletions
diff --git a/core/ContextBase.h b/core/ContextBase.h
index 7c5ac17..4ad6cb1 100644
--- a/core/ContextBase.h
+++ b/core/ContextBase.h
@@ -124,7 +124,16 @@ public:
ContextBase(const MsgTask* msgTask,
LOC_API_ADAPTER_EVENT_MASK_T exMask,
const char* libName);
- inline virtual ~ContextBase() { delete mLocApi; delete mLBSProxy; }
+ inline virtual ~ContextBase() {
+ if (nullptr != mLocApi) {
+ mLocApi->destroy();
+ mLocApi = nullptr;
+ }
+ if (nullptr != mLBSProxy) {
+ delete mLBSProxy;
+ mLBSProxy = nullptr;
+ }
+ }
inline const MsgTask* getMsgTask() { return mMsgTask; }
inline LocApiBase* getLocApi() { return mLocApi; }
diff --git a/core/LocApiBase.h b/core/LocApiBase.h
index fc86eb3..b50a973 100644
--- a/core/LocApiBase.h
+++ b/core/LocApiBase.h
@@ -103,11 +103,11 @@ class LocApiBase {
//it as a friend
friend struct LocOpenMsg;
friend struct LocCloseMsg;
+ friend struct LocKillMsg;
friend class ContextBase;
static MsgTask* mMsgTask;
LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
-
protected:
ContextBase *mContext;
virtual enum loc_api_adapter_err
@@ -118,7 +118,12 @@ protected:
LOC_API_ADAPTER_EVENT_MASK_T mMask;
LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
ContextBase* context = NULL);
- inline virtual ~LocApiBase() { close(); }
+ inline virtual ~LocApiBase() {
+ if (nullptr != mMsgTask) {
+ mMsgTask->destroy();
+ mMsgTask = nullptr;
+ }
+ }
bool isInSession();
const LOC_API_ADAPTER_EVENT_MASK_T mExcludedMask;
bool isMaster();
@@ -127,6 +132,18 @@ public:
inline void sendMsg(const LocMsg* msg) const {
mMsgTask->sendMsg(msg);
}
+ inline void destroy() {
+ close();
+ struct LocKillMsg : public LocMsg {
+ LocApiBase* mLocApi;
+ inline LocKillMsg(LocApiBase* locApi) : LocMsg(), mLocApi(locApi) {}
+ inline virtual void proc() const {
+ delete mLocApi;
+ }
+ };
+ sendMsg(new LocKillMsg(this));
+ }
+
void addAdapter(LocAdapterBase* adapter);
void removeAdapter(LocAdapterBase* adapter);