Merge "Adding Mutex for Creating Context"

This commit is contained in:
Linux Build Service Account 2015-04-14 17:49:08 -07:00 committed by Gerrit - the friendly Code Review server
commit 45e27ba7b8
2 changed files with 21 additions and 2 deletions

View file

@ -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;
}

View file

@ -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,