From 6de2e04d3c8c15cf37348a53c1a252b71675ab0e Mon Sep 17 00:00:00 2001 From: liangjunhao Date: Sat, 29 Jul 2023 01:16:22 +0000 Subject: [PATCH] fix: clean static warning Signed-off-by: liangjunhao --- services/native/include/power_mgr_notify.h | 6 +++--- services/native/include/power_mode_policy.h | 3 +++ services/native/src/power_mode_policy.cpp | 5 +++++ services/native/src/suspend/suspend_controller.cpp | 1 + services/native/src/suspend/suspend_sources.cpp | 4 ++++ services/native/src/suspend/suspend_sources.h | 3 +++ services/native/src/wakeup/wakeup_sources.cpp | 4 ++++ services/native/src/wakeup/wakeup_sources.h | 3 +++ services/zidl/src/power_mgr_proxy.cpp | 2 +- 9 files changed, 27 insertions(+), 4 deletions(-) diff --git a/services/native/include/power_mgr_notify.h b/services/native/include/power_mgr_notify.h index ec69baba..3caa601d 100644 --- a/services/native/include/power_mgr_notify.h +++ b/services/native/include/power_mgr_notify.h @@ -36,9 +36,9 @@ private: void PublishEvents(int64_t eventTime, sptr intent); - sptr screenOffWant_; - sptr screenOnWant_; - sptr publishInfo_; + sptr screenOffWant_ {nullptr}; + sptr screenOnWant_ {nullptr}; + sptr publishInfo_ {nullptr}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/power_mode_policy.h b/services/native/include/power_mode_policy.h index f2667fbe..107ca524 100644 --- a/services/native/include/power_mode_policy.h +++ b/services/native/include/power_mode_policy.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "power_save_mode.h" @@ -66,6 +67,8 @@ private: void CompareModeItem(uint32_t mode, uint32_t lastMode); int32_t GetPolicyFromMap(uint32_t type); int32_t GetRecoverPolicyFromMap(uint32_t type); + std::mutex policyMutex_; + std::mutex actionMapMutex_; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/src/power_mode_policy.cpp b/services/native/src/power_mode_policy.cpp index 27d0306e..b5610d5b 100644 --- a/services/native/src/power_mode_policy.cpp +++ b/services/native/src/power_mode_policy.cpp @@ -36,6 +36,7 @@ int32_t PowerModePolicy::GetPowerModeValuePolicy(uint32_t type) int32_t PowerModePolicy::GetPolicyFromMap(uint32_t type) { int32_t ret = INIT_VALUE_FALSE; + std::lock_guard lock(policyMutex_); valueiter = valueModePolicy.find(type); if (valueiter != valueModePolicy.end()) { ret = valueiter->second; @@ -46,6 +47,7 @@ int32_t PowerModePolicy::GetPolicyFromMap(uint32_t type) int32_t PowerModePolicy::GetRecoverPolicyFromMap(uint32_t type) { int32_t ret = INIT_VALUE_FALSE; + std::lock_guard lock(policyMutex_); recoveriter = recoverModePolicy.find(type); if (recoveriter != recoverModePolicy.end()) { ret = recoveriter->second; @@ -88,6 +90,7 @@ void PowerModePolicy::ReadRecoverPolicy(uint32_t mode) void PowerModePolicy::CompareModeItem(uint32_t mode, uint32_t lastMode) { + std::lock_guard lock(policyMutex_); recoverModePolicy.clear(); valueModePolicy.clear(); @@ -108,11 +111,13 @@ void PowerModePolicy::CompareModeItem(uint32_t mode, uint32_t lastMode) void PowerModePolicy::AddAction(uint32_t type, ModeAction& action) { POWER_HILOGD(FEATURE_POWER_MODE, "type=%{public}d", type); + std::lock_guard lock(actionMapMutex_); actionMap.emplace(type, action); } void PowerModePolicy::TriggerAllActions(bool isBoot) { + std::lock_guard lock(actionMapMutex_); for (auto iterator = actionMap.begin(); iterator != actionMap.end(); iterator++) { POWER_HILOGD(FEATURE_POWER_MODE, "type=%{public}d", iterator->first); iterator->second(isBoot); diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 171600e7..9b1567e7 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -106,6 +106,7 @@ void SuspendController::ExecSuspendMonitorByReason(SuspendDeviceType reason) auto monitor = monitorMap_[reason]; if (monitor == nullptr) { POWER_HILOGI(COMP_SVC, "get monitor fail"); + g_monitorMutex.Unlock(); return; } monitor->Notify(); diff --git a/services/native/src/suspend/suspend_sources.cpp b/services/native/src/suspend/suspend_sources.cpp index 233686b5..515c7cd0 100644 --- a/services/native/src/suspend/suspend_sources.cpp +++ b/services/native/src/suspend/suspend_sources.cpp @@ -18,6 +18,7 @@ #include namespace OHOS { namespace PowerMgr { +std::mutex SuspendSources::sourceKeysMutex_; SuspendDeviceType SuspendSources::mapSuspendDeviceType(const std::string& key) { @@ -42,6 +43,7 @@ SuspendDeviceType SuspendSources::mapSuspendDeviceType(const std::string& key) std::vector SuspendSources::getSourceKeys() { + std::lock_guard lock(sourceKeysMutex_); std::vector sourceKeys; sourceKeys.push_back(SuspendSources::POWERKEY_KEY); sourceKeys.push_back(SuspendSources::TIMEOUT_KEY); @@ -52,11 +54,13 @@ std::vector SuspendSources::getSourceKeys() void SuspendSources::PutSource(SuspendSource& source) { + std::lock_guard lock(sourceListMutex_); sourceList_.push_back(source); } std::vector SuspendSources::GetSourceList() { + std::lock_guard lock(sourceListMutex_); return sourceList_; } diff --git a/services/native/src/suspend/suspend_sources.h b/services/native/src/suspend/suspend_sources.h index 77d109b4..f631a951 100644 --- a/services/native/src/suspend/suspend_sources.h +++ b/services/native/src/suspend/suspend_sources.h @@ -19,6 +19,7 @@ #include "power_state_machine_info.h" #include #include +#include namespace OHOS { namespace PowerMgr { @@ -78,6 +79,8 @@ public: private: std::vector sourceList_; + std::mutex sourceListMutex_; + static std::mutex sourceKeysMutex_; }; } // namespace PowerMgr diff --git a/services/native/src/wakeup/wakeup_sources.cpp b/services/native/src/wakeup/wakeup_sources.cpp index 3852a9d2..35ddc5be 100644 --- a/services/native/src/wakeup/wakeup_sources.cpp +++ b/services/native/src/wakeup/wakeup_sources.cpp @@ -18,6 +18,7 @@ #include namespace OHOS { namespace PowerMgr { +std::mutex WakeupSources::sourceKeysMutex_; WakeupDeviceType WakeupSources::mapWakeupDeviceType(const std::string& key, uint32_t click) { @@ -61,6 +62,7 @@ WakeupDeviceType WakeupSources::mapWakeupDeviceType(const std::string& key, uint std::vector WakeupSources::getSourceKeys() { + std::lock_guard lock(sourceKeysMutex_); std::vector sourceKeys; sourceKeys.push_back(WakeupSources::POWERKEY_KEY); sourceKeys.push_back(WakeupSources::MOUSE_KEY); @@ -75,11 +77,13 @@ std::vector WakeupSources::getSourceKeys() void WakeupSources::PutSource(WakeupSource& source) { + std::lock_guard lock(sourceListMutex_); sourceList_.push_back(source); } std::vector WakeupSources::GetSourceList() { + std::lock_guard lock(sourceListMutex_); return sourceList_; } diff --git a/services/native/src/wakeup/wakeup_sources.h b/services/native/src/wakeup/wakeup_sources.h index d7292173..98ebce60 100644 --- a/services/native/src/wakeup/wakeup_sources.h +++ b/services/native/src/wakeup/wakeup_sources.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace OHOS { namespace PowerMgr { @@ -78,6 +79,8 @@ public: private: std::vector sourceList_; + std::mutex sourceListMutex_; + static std::mutex sourceKeysMutex_; }; } // namespace PowerMgr diff --git a/services/zidl/src/power_mgr_proxy.cpp b/services/zidl/src/power_mgr_proxy.cpp index f4a8837d..f87df705 100644 --- a/services/zidl/src/power_mgr_proxy.cpp +++ b/services/zidl/src/power_mgr_proxy.cpp @@ -830,7 +830,7 @@ PowerErrors PowerMgrProxy::IsStandby(bool& isStandby) } int32_t error; - + READ_PARCEL_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); READ_PARCEL_WITH_RET(reply, Bool, isStandby, PowerErrors::ERR_CONNECTION_FAIL); -- Gitee