From 9b2e79c42e881973d5924888022b6d3b0a89c73a Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Tue, 12 Feb 2019 18:44:00 -0800 Subject: [PATCH] Fix race condition that adapter does not get handleEngineUp - Removed redundant injectFeatureConfig() call, as it this happens twice, once when the first context is created which would have been too early and once when LocApi open success. - Resolved a race condition that second adapter added may not have been in LocApi's adapter list yet when handleEngineUp() is broadcast. Change-Id: I8ecc18eab6b450c326c0be1abc011f70285439aa CRs-Fixed: 2397902 --- core/LocApiBase.cpp | 20 +++++++++++++------- core/LocDualContext.cpp | 21 +++------------------ core/LocDualContext.h | 1 - 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index c2ee4114..13b1c71a 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -95,7 +96,10 @@ struct LocSsrMsg : public LocMsg { } inline virtual void proc() const { mLocApi->close(); - mLocApi->open(mLocApi->getEvtMask()); + if (LOC_API_ADAPTER_ERR_SUCCESS == mLocApi->open(mLocApi->getEvtMask())) { + // Notify adapters that engine up after SSR + mLocApi->handleEngineUpEvent(); + } } inline void locallog() const { LOC_LOGV("LocSsrMsg"); @@ -107,13 +111,17 @@ struct LocSsrMsg : public LocMsg { struct LocOpenMsg : public LocMsg { LocApiBase* mLocApi; - inline LocOpenMsg(LocApiBase* locApi) : - LocMsg(), mLocApi(locApi) + LocAdapterBase* mAdapter; + inline LocOpenMsg(LocApiBase* locApi, LocAdapterBase* adapter = nullptr) : + LocMsg(), mLocApi(locApi), mAdapter(adapter) { locallog(); } inline virtual void proc() const { - mLocApi->open(mLocApi->getEvtMask()); + if (LOC_API_ADAPTER_ERR_SUCCESS == mLocApi->open(mLocApi->getEvtMask()) && + nullptr != mAdapter) { + mAdapter->handleEngineUpEvent(); + } } inline void locallog() const { LOC_LOGv("LocOpen Mask: %" PRIx64 "\n", mLocApi->getEvtMask()); @@ -222,7 +230,7 @@ void LocApiBase::addAdapter(LocAdapterBase* adapter) for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) { if (mLocAdapters[i] == NULL) { mLocAdapters[i] = adapter; - mMsgTask->sendMsg(new LocOpenMsg(this)); + mMsgTask->sendMsg(new LocOpenMsg(this, adapter)); break; } } @@ -295,8 +303,6 @@ void LocApiBase::updateNmeaMask(uint32_t mask) void LocApiBase::handleEngineUpEvent() { - LocDualContext::injectFeatureConfig(mContext); - // loop through adapters, and deliver to all adapters. TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineUpEvent()); } diff --git a/core/LocDualContext.cpp b/core/LocDualContext.cpp index 180d9dca..9851d610 100644 --- a/core/LocDualContext.cpp +++ b/core/LocDualContext.cpp @@ -55,7 +55,6 @@ LocDualContext::mBgExclMask = const MsgTask* LocDualContext::mMsgTask = NULL; ContextBase* LocDualContext::mFgContext = NULL; ContextBase* LocDualContext::mBgContext = NULL; -ContextBase* LocDualContext::mInjectContext = NULL; // the name must be shorter than 15 chars const char* LocDualContext::mLocationHalName = "Loc_hal_worker"; #ifndef USE_GLIB @@ -91,11 +90,6 @@ ContextBase* LocDualContext::getLocFgContext(LocThread::tCreate tCreator, mFgContext = new LocDualContext(msgTask, mFgExclMask); } - if(NULL == mInjectContext) { - LOC_LOGD("%s:%d]: mInjectContext is FgContext", __func__, __LINE__); - mInjectContext = mFgContext; - injectFeatureConfig(mInjectContext); - } pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex); if (firstMsg) { @@ -116,11 +110,6 @@ ContextBase* LocDualContext::getLocBgContext(LocThread::tCreate tCreator, mBgContext = new LocDualContext(msgTask, mBgExclMask); } - if(NULL == mInjectContext) { - LOC_LOGD("%s:%d]: mInjectContext is BgContext", __func__, __LINE__); - mInjectContext = mBgContext; - injectFeatureConfig(mInjectContext); - } pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex); if (firstMsg) { @@ -132,13 +121,9 @@ ContextBase* LocDualContext::getLocBgContext(LocThread::tCreate tCreator, void LocDualContext :: injectFeatureConfig(ContextBase *curContext) { - LOC_LOGD("%s:%d]: Enter", __func__, __LINE__); - if(curContext == mInjectContext) { - LOC_LOGD("%s:%d]: Calling LBSProxy (%p) to inject feature config", - __func__, __LINE__, ((LocDualContext *)mInjectContext)->mLBSProxy); - ((LocDualContext *)mInjectContext)->mLBSProxy->injectFeatureConfig(curContext); - } - LOC_LOGD("%s:%d]: Exit", __func__, __LINE__); + LOC_LOGD("%s:%d]: Calling LBSProxy (%p) to inject feature config", + __func__, __LINE__, ((LocDualContext *)curContext)->mLBSProxy); + ((LocDualContext *)curContext)->mLBSProxy->injectFeatureConfig(curContext); } LocDualContext::LocDualContext(const MsgTask* msgTask, diff --git a/core/LocDualContext.h b/core/LocDualContext.h index 3b3ce2cf..edfbfb7d 100644 --- a/core/LocDualContext.h +++ b/core/LocDualContext.h @@ -40,7 +40,6 @@ class LocDualContext : public ContextBase { static const MsgTask* mMsgTask; static ContextBase* mFgContext; static ContextBase* mBgContext; - static ContextBase* mInjectContext; static const MsgTask* getMsgTask(LocThread::tCreate tCreator, const char* name, bool joinable = true); static const MsgTask* getMsgTask(const char* name, bool joinable = true);