diff --git a/application/protector/include/action/thermal_device_control.h b/application/protector/include/action/thermal_device_control.h index e7995fffe8928446da2f489997d08667b6d10290..527d241a87d4a999f4c328a092f2ea6825000b33 100644 --- a/application/protector/include/action/thermal_device_control.h +++ b/application/protector/include/action/thermal_device_control.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "ithermal_action.h" @@ -38,6 +39,7 @@ private: ThermalActionMap thermalActionMap_; std::shared_ptr thermalAction_; std::string preName_; + std::mutex mutex_; }; } // namespace PowerMgr } // namespace OHOs diff --git a/application/protector/include/policy/thermal_kernel_policy.h b/application/protector/include/policy/thermal_kernel_policy.h index 5987f4bcef29c67711f09b856cd7ae0ae9bc704c..aabe8b1f471a46aebc155ab6ff99425b4376a11b 100644 --- a/application/protector/include/policy/thermal_kernel_policy.h +++ b/application/protector/include/policy/thermal_kernel_policy.h @@ -68,7 +68,7 @@ private: LevelMap levelMap_; std::vector levelAction_; std::vector executeActionList_; - int32_t maxCd_; + int32_t maxCd_ {0}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/application/protector/include/thermal_protector_timer.h b/application/protector/include/thermal_protector_timer.h index 33dac4a9bed394cca26c3808462400ffda4baa12..6ffc72f2b74d27cd41613aba658f6c9661e57fde 100644 --- a/application/protector/include/thermal_protector_timer.h +++ b/application/protector/include/thermal_protector_timer.h @@ -53,7 +53,7 @@ private: int32_t timerInterval_ {-1}; std::map callbackHandler_; std::vector multipleList_; - int32_t reportTime_; + int32_t reportTime_ {0}; NotifyTask notify_; SensorsMap sensorMap_; std::shared_ptr provision_; diff --git a/application/protector/src/action/thermal_device_control.cpp b/application/protector/src/action/thermal_device_control.cpp index a8c3bc5398dc495242f77f1f15e535f51d2eb3cc..e4b63cfd8dd08bbb470589d3d6bf47ba4d903d0f 100644 --- a/application/protector/src/action/thermal_device_control.cpp +++ b/application/protector/src/action/thermal_device_control.cpp @@ -32,6 +32,7 @@ bool ThermalDeviceControl::Init() return false; } + std::lock_guard lock(mutex_); auto actionList = policy->GetLevelAction(); if (actionList.empty()) { return false; diff --git a/services/native/include/thermal_action/action/action_application_process.h b/services/native/include/thermal_action/action/action_application_process.h index c8035ba815521f4af87428caba4ae203c066f4dd..7ed4b8a0fed84bea8bd93d482c44b07914f8d55c 100644 --- a/services/native/include/thermal_action/action/action_application_process.h +++ b/services/native/include/thermal_action/action/action_application_process.h @@ -59,7 +59,7 @@ private: std::vector bgAppProcessInfos_; std::vector fgAppProcessInfos_; std::vector allAppProcessInfos_; - uint32_t lastValue_; + uint32_t lastValue_ {0}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/thermal_action/action/action_popup.h b/services/native/include/thermal_action/action/action_popup.h index 910519a1e9a15b53fe68f8eb0a5959e0b3cfbc4d..7de5434bd8c2616a83371f7400404e8670085528 100644 --- a/services/native/include/thermal_action/action/action_popup.h +++ b/services/native/include/thermal_action/action/action_popup.h @@ -38,7 +38,7 @@ public: private: uint32_t GetActionValue(); std::vector valueList_; - uint32_t lastValue_; + uint32_t lastValue_ {0}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/thermal_action/action/action_shutdown.h b/services/native/include/thermal_action/action/action_shutdown.h index 2d3f78d67b48000c17e03a611dae67e7605d3175..406e8fedea5a5e038f922d5a7463812ef2e61504 100644 --- a/services/native/include/thermal_action/action/action_shutdown.h +++ b/services/native/include/thermal_action/action/action_shutdown.h @@ -37,7 +37,7 @@ public: private: uint32_t GetActionValue(); std::vector valueList_; - uint32_t lastValue_; + uint32_t lastValue_ {0}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/thermal_action/action/action_soc/action_cpu_boost.h b/services/native/include/thermal_action/action/action_soc/action_cpu_boost.h index 241a5cd7c8e43539248a0e2f3b3590d3fd30215d..190b9029624be692d7fe48030afe87ef2ab4aeb6 100644 --- a/services/native/include/thermal_action/action/action_soc/action_cpu_boost.h +++ b/services/native/include/thermal_action/action/action_soc/action_cpu_boost.h @@ -16,6 +16,8 @@ #ifndef ACTION_CPU_BOOST_H #define ACTION_CPU_BOOST_H +#include + #include "soc_action_base.h" namespace OHOS { @@ -36,6 +38,7 @@ private: bool isAction_ {false}; bool actionTag_ {false}; bool lastTag_ {false}; + std::mutex sceneMutex_; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/thermal_action/action/action_thermal_level.h b/services/native/include/thermal_action/action/action_thermal_level.h index 5d37d937547713c1014d701a0346b3e4a380fd79..2fac9360cf6c218dad8a89fc63dde1ce7cc17ff4 100644 --- a/services/native/include/thermal_action/action/action_thermal_level.h +++ b/services/native/include/thermal_action/action/action_thermal_level.h @@ -73,7 +73,7 @@ private: std::string params_; static std::set, classcomp> thermalLevelListeners_; static int32_t level_; - uint32_t lastValue_; + uint32_t lastValue_ {0}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/thermal_action/action/action_voltage.h b/services/native/include/thermal_action/action/action_voltage.h index 8b6bfea464173494970eb66be086c7ea988732f5..fc46c8fd5c907660386345be4a0d323069471225 100644 --- a/services/native/include/thermal_action/action/action_voltage.h +++ b/services/native/include/thermal_action/action/action_voltage.h @@ -38,7 +38,7 @@ public: private: uint32_t GetActionValue(); std::vector valueList_; - uint32_t lastValue_; + uint32_t lastValue_ {0}; std::string protocol_; static std::vector chargeLimitList_; }; diff --git a/services/native/include/thermal_action/action/action_volume.h b/services/native/include/thermal_action/action/action_volume.h index 6944a242dd7296081d4280055aa86b76f6169a13..2649bb4b46e69006adfc30b5f775c4f702e2843c 100644 --- a/services/native/include/thermal_action/action/action_volume.h +++ b/services/native/include/thermal_action/action/action_volume.h @@ -35,7 +35,7 @@ public: private: float GetActionValue(); std::vector valueList_; - float lastValue_; + float lastValue_ {0}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/thermal_action/thermal_action_factory.h b/services/native/include/thermal_action/thermal_action_factory.h index 645eb3016b9e9adb2f5dfcac4bb74913839d392a..320a63b38f7bd311b035c2a88f0ecf4951807c4e 100644 --- a/services/native/include/thermal_action/thermal_action_factory.h +++ b/services/native/include/thermal_action/thermal_action_factory.h @@ -17,6 +17,7 @@ #define THERMAL_ACTION_FACTORY_H #include +#include #include "ithermal_action.h" diff --git a/services/native/include/thermal_observer/thermal_service_subscriber.h b/services/native/include/thermal_observer/thermal_service_subscriber.h index 5355727f47ad7013d5990c51e38c769eab924952..23fee85a1eb4af03d4753c58fd10b467041591d4 100644 --- a/services/native/include/thermal_observer/thermal_service_subscriber.h +++ b/services/native/include/thermal_observer/thermal_service_subscriber.h @@ -43,7 +43,7 @@ public: private: TypeTempMap typeTempMap_; ThermalSensorInfo::TypeHistoryMap typeHistoryMap_; - uint32_t historyCount_; + uint32_t historyCount_ {0}; time_t startTime_; time_t endTime_; std::map sensorsRateMap_; diff --git a/services/native/src/thermal_action/action/action_soc/action_cpu_boost.cpp b/services/native/src/thermal_action/action/action_soc/action_cpu_boost.cpp index 5a271bbdec616031a56d9f01ddf5b3dde9d514ab..4da7ef803915d20203c6f6b10eabfb877562f4f7 100644 --- a/services/native/src/thermal_action/action/action_soc/action_cpu_boost.cpp +++ b/services/native/src/thermal_action/action/action_soc/action_cpu_boost.cpp @@ -70,6 +70,7 @@ void ActionCpuBoost::Execute() bool ActionCpuBoost::GetActionValue() { + std::lock_guard lock(sceneMutex_); std::string scene = g_service->GetScene(); auto iter = g_sceneMap.find(scene); if (iter != g_sceneMap.end()) { diff --git a/services/native/src/thermal_action/thermal_action_factory.cpp b/services/native/src/thermal_action/thermal_action_factory.cpp index 32caca6ac755d90a3d7e084c722cbde2c33bb241..52813f70c312fb7766b110c8c4a447498201ac47 100644 --- a/services/native/src/thermal_action/thermal_action_factory.cpp +++ b/services/native/src/thermal_action/thermal_action_factory.cpp @@ -37,9 +37,11 @@ namespace OHOS { namespace PowerMgr { namespace { std::map> g_actionMap; +std::mutex g_mutex; } void ThermalActionFactory::InitFactory() { + std::lock_guard lock(g_mutex); g_actionMap.clear(); g_actionMap.insert(std::make_pair(CPU_BIG_ACTION_NAME, std::make_shared(CPU_BIG_ACTION_NAME))); g_actionMap.insert(std::make_pair(CPU_MED_ACTION_NAME, std::make_shared(CPU_MED_ACTION_NAME))); @@ -69,6 +71,7 @@ void ThermalActionFactory::InitFactory() std::shared_ptr ThermalActionFactory::Create(const std::string& actionName) { THERMAL_HILOGD(COMP_SVC, "Enter"); + std::lock_guard lock(g_mutex); for (auto iter = g_actionMap.begin(); iter != g_actionMap.end(); ++iter) { if (StringOperation::Compare(actionName, iter->first)) { return iter->second;