diff options
author | haohuang <haohuang@codeaurora.org> | 2021-04-28 17:03:50 +0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2021-09-07 01:51:47 -0700 |
commit | fd64af16b18a6864358e4392c0579251183e225d (patch) | |
tree | 28f85b945d271e06018a1e39654656d90235fe3f | |
parent | c9560c1201d115ff372c74fed296e660139e7a76 (diff) |
Resolve one race condition issue in GnssAdapter
It is possible that getServerUrl() and getMoServerUrl()
are called from different thread at same time, race
condition will happen. Move all getServerUrl() and
getMoServerUrl() to GnssAdapter's MsgTask.
Change-Id: Idb34c9993b5ddff7389272540810bcf7508b4860
CRs-Fixed: 2934832
-rw-r--r-- | gnss/GnssAdapter.cpp | 18 | ||||
-rw-r--r-- | gnss/GnssAdapter.h | 2 |
2 files changed, 14 insertions, 6 deletions
diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 1938782..29fbe95 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -889,6 +889,8 @@ GnssAdapter::setConfig() ContextBase::mGps_conf.MO_SUPL_PORT, LOC_AGPS_MO_SUPL_SERVER); + std::string moServerUrl = getMoServerUrl(); + std::string serverUrl = getServerUrl(); // inject the configurations into modem loc_gps_cfg_s gpsConf = ContextBase::mGps_conf; loc_sap_cfg_s_type sapConf = ContextBase::mSap_conf; @@ -936,8 +938,10 @@ GnssAdapter::setConfig() gnssConfigRequested.blacklistedSvIds.assign(mBlacklistedSvIds.begin(), mBlacklistedSvIds.end()); mLocApi->sendMsg(new LocApiMsg( - [this, gpsConf, sapConf, oldMoServerUrl, gnssConfigRequested] () mutable { - gnssUpdateConfig(oldMoServerUrl, gnssConfigRequested, gnssConfigRequested); + [this, gpsConf, sapConf, oldMoServerUrl, moServerUrl, + serverUrl, gnssConfigRequested] () mutable { + gnssUpdateConfig(oldMoServerUrl, moServerUrl, serverUrl, + gnssConfigRequested, gnssConfigRequested); // set nmea mask type uint32_t mask = 0; @@ -1025,6 +1029,7 @@ GnssAdapter::setConfig() } std::vector<LocationError> GnssAdapter::gnssUpdateConfig(const std::string& oldMoServerUrl, + const std::string& moServerUrl, const std::string& serverUrl, GnssConfig& gnssConfigRequested, GnssConfig& gnssConfigNeedEngineUpdate, size_t count) { loc_gps_cfg_s gpsConf = ContextBase::mGps_conf; size_t index = 0; @@ -1034,9 +1039,6 @@ std::vector<LocationError> GnssAdapter::gnssUpdateConfig(const std::string& oldM errsList.insert(errsList.begin(), count, LOCATION_ERROR_SUCCESS); } - std::string serverUrl = getServerUrl(); - std::string moServerUrl = getMoServerUrl(); - int serverUrlLen = serverUrl.length(); int moServerUrlLen = moServerUrl.length(); @@ -1424,10 +1426,14 @@ GnssAdapter::gnssUpdateConfigCommand(const GnssConfig& config) adapter.reportResponse(countOfConfigs, errs.data(), ids.data()); }); + std::string moServerUrl = adapter.getMoServerUrl(); + std::string serverUrl = adapter.getServerUrl(); mApi.sendMsg(new LocApiMsg( [&adapter, gnssConfigRequested, gnssConfigNeedEngineUpdate, - countOfConfigs, configCollectiveResponse, errs] () mutable { + moServerUrl, serverUrl, countOfConfigs, configCollectiveResponse, + errs] () mutable { std::vector<LocationError> errsList = adapter.gnssUpdateConfig("", + moServerUrl, serverUrl, gnssConfigRequested, gnssConfigNeedEngineUpdate, countOfConfigs); configCollectiveResponse->returnToSender(errsList); diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 6b8d024..2cd4a5c 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -409,6 +409,8 @@ public: void deleteAidingData(const GnssAidingData &data, uint32_t sessionId); void gnssUpdateXtraThrottleCommand(const bool enabled); std::vector<LocationError> gnssUpdateConfig(const std::string& oldMoServerUrl, + const std::string& moServerUrl, + const std::string& serverUrl, GnssConfig& gnssConfigRequested, GnssConfig& gnssConfigNeedEngineUpdate, size_t count = 0); |