diff --git a/services/tel_ril/include/tel_ril_base.h b/services/tel_ril/include/tel_ril_base.h index 2501574d8..2c565bf37 100644 --- a/services/tel_ril/include/tel_ril_base.h +++ b/services/tel_ril/include/tel_ril_base.h @@ -57,6 +57,7 @@ public: static std::shared_ptr CreateTelRilRequest(const AppExecFwk::InnerEvent::Pointer &result); void ResetRilInterface(sptr rilInterface); + sptr GetRilInterface(); static std::shared_ptr FindTelRilRequest(const RadioResponseInfo &responseInfo); int32_t ErrorResponse(std::shared_ptr telRilRequest, const RadioResponseInfo &responseInfo); @@ -114,7 +115,8 @@ template inline int32_t TelRilBase::Request(const char *funcName, const AppExecFwk::InnerEvent::Pointer &response, FuncType &&_func, ParamTypes &&... _args) { - if (rilInterface_ == nullptr) { + sptr rilInterface = GetRilInterface(); + if (rilInterface == nullptr) { TELEPHONY_LOGE("%{public}s() rilInterface_ is null", funcName); return TELEPHONY_ERR_LOCAL_PTR_NULL; } @@ -123,7 +125,7 @@ inline int32_t TelRilBase::Request(const char *funcName, const AppExecFwk::Inner TELEPHONY_LOGE("%{public}s() telRilRequest is null", funcName); return TELEPHONY_ERR_LOCAL_PTR_NULL; } - return (rilInterface_->*(_func))(slotId_, telRilRequest->serialId_, std::forward(_args)...); + return (rilInterface->*(_func))(slotId_, telRilRequest->serialId_, std::forward(_args)...); } inline int32_t TelRilBase::Response(const char *funcName, const HDI::Ril::V1_1::RilRadioResponseInfo &iResponseInfo) diff --git a/services/tel_ril/src/tel_ril_base.cpp b/services/tel_ril/src/tel_ril_base.cpp index ee6af1ea7..4e45a0396 100644 --- a/services/tel_ril/src/tel_ril_base.cpp +++ b/services/tel_ril/src/tel_ril_base.cpp @@ -22,6 +22,7 @@ namespace Telephony { std::atomic_int TelRilBase::nextSerialId_(1); std::unordered_map> TelRilBase::requestMap_; std::mutex TelRilBase::requestLock_; +std::mutex dealLock_; std::shared_ptr TelRilBase::handler_; TelRilBase::TelRilBase(int32_t slotId, sptr rilInterface, @@ -33,9 +34,16 @@ TelRilBase::TelRilBase(int32_t slotId, sptr rilInterface, void TelRilBase::ResetRilInterface(sptr rilInterface) { + std::lock_guard lock(dealLock_); rilInterface_ = rilInterface; } +sptr TelRilBase::GetRilInterface() +{ + std::lock_guard lock(dealLock_); + return rilInterface_; +} + std::shared_ptr TelRilBase::CreateTelRilRequest(const AppExecFwk::InnerEvent::Pointer &result) { std::shared_ptr telRilRequest = std::make_shared(GetNextSerialId(), result); @@ -83,7 +91,7 @@ std::shared_ptr TelRilBase::FindTelRilRequest(const RadioResponse int32_t TelRilBase::GetSerialId(const AppExecFwk::InnerEvent::Pointer &response) { - if (rilInterface_ == nullptr) { + if (GetRilInterface() == nullptr) { TELEPHONY_LOGE("ERROR : rilInterface_ == nullptr !!!"); return -TELEPHONY_ERR_ARGUMENT_INVALID; }