summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorKevin Tang <zhikait@codeaurora.org>2019-02-12 18:44:00 -0800
committerKevin Tang <zhikait@codeaurora.org>2019-02-14 11:08:21 -0800
commit9b2e79c42e881973d5924888022b6d3b0a89c73a (patch)
tree487eeab66e3cf828593a2261ac1735d6434f3b36 /core
parent9e2e7b8004f1f525174a49648b5fd37bb169a3c8 (diff)
downloadgps-9b2e79c42e881973d5924888022b6d3b0a89c73a.tar.gz
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
Diffstat (limited to 'core')
-rw-r--r--core/LocApiBase.cpp20
-rw-r--r--core/LocDualContext.cpp21
-rw-r--r--core/LocDualContext.h1
3 files changed, 16 insertions, 26 deletions
diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp
index c2ee411..13b1c71 100644
--- a/core/LocApiBase.cpp
+++ b/core/LocApiBase.cpp
@@ -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());
}
diff --git a/core/LocDualContext.cpp b/core/LocDualContext.cpp
index 180d9dc..9851d61 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 3b3ce2c..edfbfb7 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);