Adding Mutex for Creating Context
Adding lock for creating foreground context and background context, preventing any possible race condition. CRs-fixed: 820078 Change-Id: I7ace685622904ee2aa12f317540f9c04880acc70
This commit is contained in:
parent
e7fa3e15ae
commit
7fa3b1bd2a
2 changed files with 21 additions and 2 deletions
|
@ -61,6 +61,8 @@ ContextBase* LocDualContext::mInjectContext = NULL;
|
|||
const char* LocDualContext::mLocationHalName = "Loc_hal_worker";
|
||||
const char* LocDualContext::mLBSLibName = "liblbs_core.so";
|
||||
|
||||
pthread_mutex_t LocDualContext::mGetLocContextMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
const MsgTask* LocDualContext::getMsgTask(MsgTask::tCreate tCreator,
|
||||
const char* name)
|
||||
{
|
||||
|
@ -84,22 +86,30 @@ const MsgTask* LocDualContext::getMsgTask(MsgTask::tAssociate tAssociate,
|
|||
ContextBase* LocDualContext::getLocFgContext(MsgTask::tCreate tCreator,
|
||||
const char* name)
|
||||
{
|
||||
pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
|
||||
LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__);
|
||||
if (NULL == mFgContext) {
|
||||
LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__);
|
||||
const MsgTask* msgTask = getMsgTask(tCreator, name);
|
||||
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);
|
||||
return mFgContext;
|
||||
}
|
||||
|
||||
ContextBase* LocDualContext::getLocFgContext(MsgTask::tAssociate tAssociate,
|
||||
const char* name)
|
||||
const char* name)
|
||||
{
|
||||
pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
|
||||
LOC_LOGD("%s:%d]: querying ContextBase with tAssociate", __func__, __LINE__);
|
||||
if (NULL == mFgContext) {
|
||||
LOC_LOGD("%s:%d]: creating msgTask with tAssociate", __func__, __LINE__);
|
||||
const MsgTask* msgTask = getMsgTask(tAssociate, name);
|
||||
mFgContext = new LocDualContext(msgTask,
|
||||
mFgExclMask);
|
||||
|
@ -109,14 +119,17 @@ ContextBase* LocDualContext::getLocFgContext(MsgTask::tAssociate tAssociate,
|
|||
mInjectContext = mFgContext;
|
||||
injectFeatureConfig(mInjectContext);
|
||||
}
|
||||
pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
|
||||
return mFgContext;
|
||||
|
||||
}
|
||||
|
||||
ContextBase* LocDualContext::getLocBgContext(MsgTask::tCreate tCreator,
|
||||
const char* name)
|
||||
{
|
||||
pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
|
||||
LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__);
|
||||
if (NULL == mBgContext) {
|
||||
LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__);
|
||||
const MsgTask* msgTask = getMsgTask(tCreator, name);
|
||||
mBgContext = new LocDualContext(msgTask,
|
||||
mBgExclMask);
|
||||
|
@ -126,13 +139,17 @@ ContextBase* LocDualContext::getLocBgContext(MsgTask::tCreate tCreator,
|
|||
mInjectContext = mBgContext;
|
||||
injectFeatureConfig(mInjectContext);
|
||||
}
|
||||
pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
|
||||
return mBgContext;
|
||||
}
|
||||
|
||||
ContextBase* LocDualContext::getLocBgContext(MsgTask::tAssociate tAssociate,
|
||||
const char* name)
|
||||
{
|
||||
pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
|
||||
LOC_LOGD("%s:%d]: querying ContextBase with tAssociate", __func__, __LINE__);
|
||||
if (NULL == mBgContext) {
|
||||
LOC_LOGD("%s:%d]: creating msgTask with tAssociate", __func__, __LINE__);
|
||||
const MsgTask* msgTask = getMsgTask(tAssociate, name);
|
||||
mBgContext = new LocDualContext(msgTask,
|
||||
mBgExclMask);
|
||||
|
@ -142,6 +159,7 @@ ContextBase* LocDualContext::getLocBgContext(MsgTask::tAssociate tAssociate,
|
|||
mInjectContext = mBgContext;
|
||||
injectFeatureConfig(mInjectContext);
|
||||
}
|
||||
pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
|
||||
return mBgContext;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ class LocDualContext : public ContextBase {
|
|||
const char* name);
|
||||
static const MsgTask* getMsgTask(MsgTask::tAssociate tAssociate,
|
||||
const char* name);
|
||||
static pthread_mutex_t mGetLocContextMutex;
|
||||
|
||||
protected:
|
||||
LocDualContext(const MsgTask* msgTask,
|
||||
|
|
Loading…
Reference in a new issue