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
This commit is contained in:
parent
9e2e7b8004
commit
9b2e79c42e
3 changed files with 16 additions and 26 deletions
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <dlfcn.h>
|
||||
#include <inttypes.h>
|
||||
#include <gps_extended_c.h>
|
||||
#include <LocApiBase.h>
|
||||
#include <LocAdapterBase.h>
|
||||
#include <log_util.h>
|
||||
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue