diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index bc2916c55d82ca50d5df11ec29cf8509194d6c0f..d2ca25d313b3fa2a4ab202eedbfb323f4826af2a 100644 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -93,6 +93,7 @@ ohos_executable("samgr") { defines += [ "CONFIG_USE_JEMALLOC_DFX_INTF" ] } } + defines += ["SAMGR_USE_FFRT"] if (is_standard_system) { external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/services/samgr/native/include/collect/common_event_collect.h b/services/samgr/native/include/collect/common_event_collect.h index 36ab8104516bd76f09ad92fda5a113e6c57184a5..3652d050f9679071daf5f2e87cb493b11bf41996 100644 --- a/services/samgr/native/include/collect/common_event_collect.h +++ b/services/samgr/native/include/collect/common_event_collect.h @@ -16,7 +16,6 @@ #define SYSTEM_ABILITY_MANAGER_COMMON_EVENT_COLLECT_H #include -#include #include #include "common_event_subscriber.h" @@ -72,21 +71,21 @@ private: bool GetCpuTimes(const char* file, uint64_t& total, uint64_t& idle); float GetCpuUsage(const char* file, uint32_t interval); void MonitorCpuUsageThread(); - std::mutex commomEventLock_; - std::mutex commonEventSubscriberLock_; + samgr::mutex commomEventLock_; + samgr::mutex commonEventSubscriberLock_; sptr commonEventDeath_; std::set commonEventNames_; std::shared_ptr workHandler_; std::shared_ptr unsubHandler_; std::shared_ptr commonEventSubscriber_ = nullptr; - std::mutex commonEventStateLock_; + samgr::mutex commonEventStateLock_; std::set commonEventWhitelist; std::map> commonEventConditionExtraData_; std::map commonEventConditionValue_; - std::mutex extraDataLock_; + samgr::mutex extraDataLock_; int64_t extraDataId_ = 0; std::map extraDatas_; - std::mutex saExtraDataIdLock_; + samgr::mutex saExtraDataIdLock_; std::map> saExtraDataIdMap_; std::atomic isAwakeNotified_ {false}; std::atomic isTriggerTaskStart_ {false}; diff --git a/services/samgr/native/include/collect/device_networking_collect.h b/services/samgr/native/include/collect/device_networking_collect.h index 3836e4ec8f4c44faceb0397c7921a88db3cfc5cb..7f7bbfad7ca4de82db8bc9c9dffdbdc2e0bfd35e 100644 --- a/services/samgr/native/include/collect/device_networking_collect.h +++ b/services/samgr/native/include/collect/device_networking_collect.h @@ -17,7 +17,6 @@ #define OHOS_SYSTEM_ABILITY_MANAGER_DEVICE_NETWORKING_COLLECT_H #include "icollect_plugin.h" -#include #include #include "device_manager.h" @@ -38,7 +37,7 @@ class DeviceStateCallback : public DistributedHardware::DeviceStateCallback { private: sptr collect_; std::set deviceOnlineSet_; - std::mutex deviceOnlineLock_; + samgr::mutex deviceOnlineLock_; }; class WorkHandler; diff --git a/services/samgr/native/include/collect/device_param_collect.h b/services/samgr/native/include/collect/device_param_collect.h index f4d48ace0094895f5f20d95e1b8d9e10151f70ee..36f306b4e8c99445348966f90d9c1cbbae55fb9f 100644 --- a/services/samgr/native/include/collect/device_param_collect.h +++ b/services/samgr/native/include/collect/device_param_collect.h @@ -17,6 +17,7 @@ #define OHOS_SYSTEM_ABILITY_MANAGER_DEVICE_PARAM_COLLECT_H #include "icollect_plugin.h" +#include "samgr_ffrt_api.h" #include "system_ability_status_change_stub.h" #include #include @@ -35,7 +36,7 @@ public: int32_t OnStop() override; const std::vector& GetLowMemPrepareList() override; private: - std::mutex paramLock_; + samgr::mutex paramLock_; std::set pendingParams_; std::set params_; std::vector lowMemPrepareList_; diff --git a/services/samgr/native/include/collect/device_status_collect_manager.h b/services/samgr/native/include/collect/device_status_collect_manager.h index 602b9331747d21f1717302743582322170b83ade..179da19a7a908dda8fcf934b6ebf6b2fff9e2443 100644 --- a/services/samgr/native/include/collect/device_status_collect_manager.h +++ b/services/samgr/native/include/collect/device_status_collect_manager.h @@ -18,7 +18,6 @@ #include #include -#include #include "ffrt_handler.h" #include "icollect_plugin.h" @@ -73,7 +72,7 @@ private: int32_t RemoveUnusedEventsLocked(const std::vector& events); std::map> collectPluginMap_; std::shared_ptr collectHandler_; - std::shared_mutex saProfilesLock_; + samgr::shared_mutex saProfilesLock_; std::list onDemandSaProfiles_; }; } // namespace OHOS diff --git a/services/samgr/native/include/collect/device_switch_collect.h b/services/samgr/native/include/collect/device_switch_collect.h index d4f0878a4402f25f0002901a8be031aeb6acb035..5a18a5f4df4f777a40a2ca6696c5f76b7b80df88 100644 --- a/services/samgr/native/include/collect/device_switch_collect.h +++ b/services/samgr/native/include/collect/device_switch_collect.h @@ -19,6 +19,7 @@ #include #include "common_event_subscriber.h" +#include "samgr_ffrt_api.h" #include "icollect_plugin.h" #include "system_ability_status_change_stub.h" @@ -39,7 +40,7 @@ private: void OnReceiveWifiEvent(const EventFwk::CommonEventData& data); void OnReceiveBluetoothEvent(const EventFwk::CommonEventData& data); void ReportEvent(const OnDemandEvent& event); - std::mutex isListenEventLock_; + samgr::mutex isListenEventLock_; bool isListenSwitchEvent_ = false; wptr deviceSwitchCollect_; }; diff --git a/services/samgr/native/include/collect/device_timed_collect.h b/services/samgr/native/include/collect/device_timed_collect.h index fec2fc35bd5ce98af7abf9fd581f9a937c557856..3a8bdedb6ff32147b07807eaf5fce2d74c4202e8 100644 --- a/services/samgr/native/include/collect/device_timed_collect.h +++ b/services/samgr/native/include/collect/device_timed_collect.h @@ -20,8 +20,8 @@ #include "device_timed_collect_tool.h" #endif #include "icollect_plugin.h" +#include "samgr_ffrt_api.h" -#include #include namespace OHOS { @@ -65,13 +65,13 @@ private: void RemoveTimesInfo(const OnDemandEvent& onDemandEvent, int32_t interval); std::set nonPersitenceLoopEventSet_; std::set persitenceLoopEventSet_; - std::mutex nonPersitenceLoopEventSetLock_; - std::mutex nonPersitenceTimedEventSetLock; - std::mutex persitenceLoopEventSetLock_; - std::mutex persitenceTimedEventSetLock_; + samgr::mutex nonPersitenceLoopEventSetLock_; + samgr::mutex nonPersitenceTimedEventSetLock; + samgr::mutex persitenceLoopEventSetLock_; + samgr::mutex persitenceTimedEventSetLock_; std::map> nonPersitenceLoopTasks_; std::map> persitenceLoopTasks_; - std::mutex timeInfosLock_; + samgr::mutex timeInfosLock_; std::map timeInfos_; #ifdef PREFERENCES_ENABLE std::shared_ptr preferencesUtil_; diff --git a/services/samgr/native/include/concurrent_map.h b/services/samgr/native/include/concurrent_map.h index 58c8f2f4388ede458fcf90d6fe358c5a624654b1..38ebe427be4ce185d811678bc64bbb1dce4b87b3 100644 --- a/services/samgr/native/include/concurrent_map.h +++ b/services/samgr/native/include/concurrent_map.h @@ -17,9 +17,10 @@ #define OHOS_SAMGR_CONCURRENT_MAP_H #include -#include #include +#include "samgr_ffrt_api.h" + namespace OHOS { template class ConcurrentMap { public: @@ -44,27 +45,27 @@ public: // when multithread calling size() return a tmp status, some threads may insert just after size() call int Size() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); return map_.size(); } // when multithread calling Empty() return a tmp status, some threads may insert just after Empty() call bool IsEmpty() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); return map_.empty(); } bool Insert(const K &key, const V &value) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto ret = map_.insert(std::pair(key, value)); return ret.second; } bool FirstInsert(const K &key, const V &value) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto isFirst = map_.empty(); auto ret = map_.insert(std::pair(key, value)); // find key and cannot insert @@ -77,7 +78,7 @@ public: void EnsureInsert(const K &key, const V &value) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto ret = map_.insert(std::pair(key, value)); // find key and cannot insert if (!ret.second) { @@ -91,7 +92,7 @@ public: bool Find(const K &key, V &value) { bool ret = false; - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto iter = map_.find(key); if (iter != map_.end()) { @@ -104,20 +105,20 @@ public: void Erase(const K &key) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); map_.erase(key); } void Clear() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); map_.clear(); return; } void Clear(std::function func) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (auto iter = map_.begin(); iter != map_.end(); iter++) { func(iter->first); } @@ -126,7 +127,7 @@ public: } private: - std::mutex mutex_; + samgr::mutex mutex_; std::map map_; }; } // namespace OHOS diff --git a/services/samgr/native/include/ffrt_handler.h b/services/samgr/native/include/ffrt_handler.h index 9ad53963fec7f4fcd2e0a9d1bb963ba6a33663d0..67edf3c678e8f130e3a9de74e223a12f29a8d831 100644 --- a/services/samgr/native/include/ffrt_handler.h +++ b/services/samgr/native/include/ffrt_handler.h @@ -17,10 +17,10 @@ #define OHOS_SAMGR_FFRT_HANDLER_H #include -#include #include #include "ffrt.h" +#include "samgr_ffrt_api.h" namespace OHOS { class FFRTHandler { @@ -37,7 +37,7 @@ public: void SetFfrt(const std::string& name); private: - std::shared_mutex mutex_; + samgr::shared_mutex mutex_; std::map taskMap_; std::shared_ptr queue_; }; diff --git a/services/samgr/native/include/samgr_ffrt_api.h b/services/samgr/native/include/samgr_ffrt_api.h new file mode 100644 index 0000000000000000000000000000000000000000..c715543c91e02d313c1ab9d5f1d5bf09060bbe19 --- /dev/null +++ b/services/samgr/native/include/samgr_ffrt_api.h @@ -0,0 +1,35 @@ +/* +* Copyright (C) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef SAMGR_FFRT_API_H +#define SAMGR_FFRT_API_H + +#ifdef SAMGR_USE_FFRT +#include "ffrt.h" +namespace samgr { + using mutex = ffrt::mutex; + using shared_mutex = ffrt::shared_mutex; +} + +#else +#include +#include +namespace samgr { + using mutex = std::mutex; + using shared_mutex = std::shared_mutex; +} + +#endif // SAMGR_USE_FFRT +#endif // SAMGR_FFRT_API_H \ No newline at end of file diff --git a/services/samgr/native/include/samgr_time_handler.h b/services/samgr/native/include/samgr_time_handler.h index aa2be4f5b00dc98f40540e911f422b722e2aaca8..402d1350230cbd89a0cd7d3506662cc2f442a978 100644 --- a/services/samgr/native/include/samgr_time_handler.h +++ b/services/samgr/native/include/samgr_time_handler.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include namespace OHOS { diff --git a/services/samgr/native/include/schedule/system_ability_state_context.h b/services/samgr/native/include/schedule/system_ability_state_context.h index a569404127d5bbc321f1f63b83364f9e259d8527..af34a53d80abcf0bf9063e08429a507c0770718b 100644 --- a/services/samgr/native/include/schedule/system_ability_state_context.h +++ b/services/samgr/native/include/schedule/system_ability_state_context.h @@ -19,10 +19,9 @@ #include #include #include -#include #include -#include +#include "samgr_ffrt_api.h" #include "refbase.h" #include "sa_profiles.h" #include "isystem_ability_load_callback.h" @@ -66,8 +65,8 @@ struct UnloadRequestInfo { }; struct SystemProcessContext { - std::mutex stateCountLock; - std::mutex processLock; + samgr::mutex stateCountLock; + samgr::mutex processLock; std::u16string processName; std::list saList; std::map abilityStateCountMap; diff --git a/services/samgr/native/include/schedule/system_ability_state_scheduler.h b/services/samgr/native/include/schedule/system_ability_state_scheduler.h index 842ec7c103b390343866d001036a8ff54206e242..da80d6d8d45a4b9ab58d971baf660aa3a9ec9fb9 100644 --- a/services/samgr/native/include/schedule/system_ability_state_scheduler.h +++ b/services/samgr/native/include/schedule/system_ability_state_scheduler.h @@ -18,9 +18,7 @@ #include #include -#include #include -#include #include "ffrt_handler.h" #include "isystem_process_status_change.h" @@ -161,18 +159,18 @@ private: }; std::shared_ptr stateMachine_; std::shared_ptr stateEventHandler_; - std::shared_mutex abiltyMapLock_; - std::shared_mutex processMapLock_; + samgr::shared_mutex abiltyMapLock_; + samgr::shared_mutex processMapLock_; std::map> abilityContextMap_; std::map> processContextMap_; std::shared_ptr unloadEventHandler_; std::shared_ptr processHandler_; - std::shared_mutex listenerSetLock_; + samgr::shared_mutex listenerSetLock_; std::list> processListeners_; sptr processListenerDeath_; - std::mutex startEnableOnceLock_; + samgr::mutex startEnableOnceLock_; std::map> startEnableOnceMap_; - std::mutex stopEnableOnceLock_; + samgr::mutex stopEnableOnceLock_; std::map> stopEnableOnceMap_; }; } // namespace OHOS diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index 9ae8151c82bb4e71f2bd2453cf088983b556534c..834f5593ebe5f28a2116967ff1629b5ad6c235c1 100644 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -17,9 +17,7 @@ #define SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_H #include -#include #include -#include #include #include @@ -72,7 +70,7 @@ public: } static sptr GetInstance() { - std::lock_guard autoLock(instanceLock); + std::lock_guard autoLock(instanceLock); if (instance == nullptr) { instance = new SystemAbilityManager; } @@ -285,7 +283,7 @@ private: void DoInsertSaData(const std::u16string& name, const sptr& ability, const SAExtraProp& extraProp); int32_t StartOnDemandAbility(int32_t systemAbilityId, bool& isExist) { - std::lock_guard onDemandAbilityLock(onDemandLock_); + std::lock_guard onDemandAbilityLock(onDemandLock_); return StartOnDemandAbilityLocked(systemAbilityId, isExist); } int32_t StartOnDemandAbilityLocked(int32_t systemAbilityId, bool& isExist); @@ -298,7 +296,7 @@ private: void InitSaProfile(); bool GetSaProfile(int32_t saId, CommonSaProfile& saProfile) { - std::lock_guard autoLock(saProfileMapLock_); + std::lock_guard autoLock(saProfileMapLock_); auto iter = saProfileMap_.find(saId); if (iter == saProfileMap_.end()) { return false; @@ -326,7 +324,7 @@ private: const OnDemandEvent& event); void StartOnDemandAbility(const std::u16string& name, int32_t systemAbilityId) { - std::lock_guard autoLock(onDemandLock_); + std::lock_guard autoLock(onDemandLock_); StartOnDemandAbilityLocked(name, systemAbilityId); } void StartOnDemandAbilityLocked(const std::u16string& name, int32_t systemAbilityId); @@ -335,7 +333,7 @@ private: int32_t StartDynamicSystemProcess(const std::u16string& name, int32_t systemAbilityId, const OnDemandEvent& event); bool StopOnDemandAbility(const std::u16string& name, int32_t systemAbilityId, const OnDemandEvent& event) { - std::lock_guard autoLock(onDemandLock_); + std::lock_guard autoLock(onDemandLock_); return StopOnDemandAbilityInner(name, systemAbilityId, event); } bool StopOnDemandAbilityInner(const std::u16string& name, int32_t systemAbilityId, const OnDemandEvent& event); @@ -383,7 +381,7 @@ private: std::u16string deviceName_; static sptr instance; - static std::mutex instanceLock; + static samgr::mutex instanceLock; sptr abilityDeath_; sptr systemProcessDeath_; sptr abilityStatusDeath_; @@ -394,26 +392,26 @@ private: std::shared_ptr rpcCallbackImp_; #ifdef SAMGR_ENABLE_DELAY_DBINDER - std::shared_mutex dBinderServiceLock_; + samgr::shared_mutex dBinderServiceLock_; std::list distributedSaList_; bool isDbinderServiceInit_ = false; #endif // must hold abilityMapLock_ never access other locks - std::shared_mutex abilityMapLock_; + samgr::shared_mutex abilityMapLock_; std::map abilityMap_; // maybe hold listenerMapLock_ and then access onDemandLock_ - std::mutex listenerMapLock_; + samgr::mutex listenerMapLock_; std::map> listenerMap_; std::map subscribeCountMap_; - std::mutex onDemandLock_; + samgr::mutex onDemandLock_; std::map onDemandAbilityMap_; std::map startingAbilityMap_; - std::mutex systemProcessMapLock_; + samgr::mutex systemProcessMapLock_; std::map> systemProcessMap_; - std::mutex startingProcessMapLock_; + samgr::mutex startingProcessMapLock_; std::map startingProcessMap_; std::map callbackCountMap_; @@ -421,11 +419,11 @@ private: std::map saProfileMap_; std::set onDemandSaIdsSet_; - std::mutex saProfileMapLock_; - std::mutex loadRemoteLock_; + samgr::mutex saProfileMapLock_; + samgr::mutex loadRemoteLock_; std::map>> remoteCallbacks_; // key : said_deviceId - std::mutex saFrequencyLock_; + samgr::mutex saFrequencyLock_; std::map saFrequencyMap_; // {pid_said, count} std::unique_ptr reportEventTimer_; diff --git a/services/samgr/native/include/system_ability_manager_dumper.h b/services/samgr/native/include/system_ability_manager_dumper.h index f0091025e20ed5eab23d005d5eaeb050a132c345..a7099fc9116a7079c3982fb7de33958e69292410 100644 --- a/services/samgr/native/include/system_ability_manager_dumper.h +++ b/services/samgr/native/include/system_ability_manager_dumper.h @@ -100,7 +100,7 @@ private: static std::shared_ptr handler_; static char* ffrtMetricBuffer; static bool collectEnable; - static std::mutex ffrtMetricLock; + static samgr::mutex ffrtMetricLock; }; } // namespace OHOS #endif // SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H \ No newline at end of file diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index 2b01a069b5dbd01a265610f64600caddab7f11bb..0510e008ae7c18763aeeab67dc6db38e75bb00e4 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -69,7 +69,7 @@ CommonEventCollect::CommonEventCollect(const sptr& report) void CommonEventCollect::RemoveWhiteCommonEvent() { - std::lock_guard autoLock(commonEventStateLock_); + std::lock_guard autoLock(commonEventStateLock_); commonEventWhitelist.erase(EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); HILOGI("rm USER_UNLOCKED,size=%{public}zu", commonEventWhitelist.size()); } @@ -124,7 +124,7 @@ int32_t CommonEventCollect::OnStop() void CommonEventCollect::InitCommonEventState(const OnDemandEvent& event) { if (event.eventId == COMMON_EVENT) { - std::lock_guard autoLock(commomEventLock_); + std::lock_guard autoLock(commomEventLock_); commonEventNames_.insert(event.name); } for (auto& condition : event.conditions) { @@ -132,11 +132,11 @@ void CommonEventCollect::InitCommonEventState(const OnDemandEvent& event) continue; } { - std::lock_guard autoLock(commomEventLock_); + std::lock_guard autoLock(commomEventLock_); commonEventNames_.insert(condition.name); } if (condition.extraMessages.size() > 0) { - std::lock_guard autoLock(commonEventStateLock_); + std::lock_guard autoLock(commonEventStateLock_); for (auto [key, value] : condition.extraMessages) { commonEventConditionExtraData_[condition.name][key] = ""; } @@ -147,13 +147,13 @@ void CommonEventCollect::InitCommonEventState(const OnDemandEvent& event) void CommonEventCollect::Init(const std::list& onDemandSaProfiles) { { - std::lock_guard autoLock(commonEventStateLock_); + std::lock_guard autoLock(commonEventStateLock_); commonEventWhitelist.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); commonEventWhitelist.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING); commonEventWhitelist.insert(EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED); } { - std::lock_guard autoLock(commomEventLock_); + std::lock_guard autoLock(commomEventLock_); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING); @@ -178,7 +178,7 @@ void CommonEventCollect::Init(const std::list& onDemandSaProfiles) void CommonEventCollect::AddSkillsEvent(EventFwk::MatchingSkills& skill) { - std::lock_guard autoLock(commomEventLock_); + std::lock_guard autoLock(commomEventLock_); for (auto& commonEventName : commonEventNames_) { HILOGD("CommonEventCollect add event: %{public}s", commonEventName.c_str()); skill.AddEvent(commonEventName); @@ -192,16 +192,16 @@ void CommonEventCollect::CleanFailedEventLocked(const std::vector& return; } EventFwk::MatchingSkills skill = commonEventSubscriber_->GetSubscribeInfo().GetMatchingSkills(); + std::lock_guard autoLock(commomEventLock_); for (auto& eventName : eventNames) { skill.RemoveEvent(eventName); - std::lock_guard autoLock(commomEventLock_); commonEventNames_.erase(eventName); } } bool CommonEventCollect::CreateCommonEventSubscriber() { - std::lock_guard autoLock(commonEventSubscriberLock_); + std::lock_guard autoLock(commonEventSubscriberLock_); return CreateCommonEventSubscriberLocked(); } @@ -266,7 +266,7 @@ void CommonEventListener::OnRemoveSystemAbility(int32_t systemAblityId, const st void CommonEventCollect::SaveAction(const std::string& action) { - std::lock_guard autoLock(commonEventStateLock_); + std::lock_guard autoLock(commonEventStateLock_); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) { commonEventWhitelist.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); commonEventWhitelist.erase(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); @@ -292,7 +292,7 @@ void CommonEventCollect::SaveAction(const std::string& action) bool CommonEventCollect::CheckCondition(const OnDemandCondition& condition) { - std::lock_guard autoLock(commonEventStateLock_); + std::lock_guard autoLock(commonEventStateLock_); std::map stateMap = commonEventConditionExtraData_[condition.name]; for (auto [key, profileValue] : condition.extraMessages) { if (!ParseUtil::CheckLogicRelationship(stateMap[key], profileValue)) { @@ -374,7 +374,7 @@ int64_t CommonEventCollect::SaveOnDemandReasonExtraData(const EventFwk::CommonEv wantMap[BUNDLE_NAME] = want.GetBundle(); int64_t extraDataId = 0; { - std::lock_guard autoLock(extraDataLock_); + std::lock_guard autoLock(extraDataLock_); wantMap[COMMON_EVENT_ACTION_NAME] = want.GetAction(); OnDemandReasonExtraData extraData(data.GetCode(), data.GetData(), wantMap); @@ -393,7 +393,7 @@ int64_t CommonEventCollect::SaveOnDemandReasonExtraData(const EventFwk::CommonEv void CommonEventCollect::SaveOnDemandConditionExtraData(const EventFwk::CommonEventData& data) { - std::lock_guard autoLock(commonEventStateLock_); + std::lock_guard autoLock(commonEventStateLock_); AAFwk::Want want = data.GetWant(); commonEventConditionValue_[want.GetAction()] = std::to_string(data.GetCode()); for (auto& [key, value] : commonEventConditionExtraData_[want.GetAction()]) { @@ -404,7 +404,7 @@ void CommonEventCollect::SaveOnDemandConditionExtraData(const EventFwk::CommonEv void CommonEventCollect::RemoveOnDemandReasonExtraData(int64_t extraDataId) { { - std::lock_guard autoLock(extraDataLock_); + std::lock_guard autoLock(extraDataLock_); extraDatas_.erase(extraDataId); } HILOGD("CommonEventCollect remove extraData %{public}d", static_cast(extraDataId)); @@ -413,7 +413,7 @@ void CommonEventCollect::RemoveOnDemandReasonExtraData(int64_t extraDataId) bool CommonEventCollect::GetOnDemandReasonExtraData(int64_t extraDataId, OnDemandReasonExtraData& extraData) { - std::lock_guard autoLock(extraDataLock_); + std::lock_guard autoLock(extraDataLock_); HILOGD("CommonEventCollect get extraData %{public}d", static_cast(extraDataId)); if (extraDatas_.count(extraDataId) == 0) { return false; @@ -436,7 +436,7 @@ void CommonEventCollect::SaveCacheCommonEventSaExtraId(const OnDemandEvent& even void CommonEventCollect::SaveSaExtraDataId(int32_t saId, int64_t extraDataId) { - std::lock_guard autoLock(saExtraDataIdLock_); + std::lock_guard autoLock(saExtraDataIdLock_); auto& extraIdList = saExtraDataIdMap_[saId]; extraIdList.emplace_back(extraDataId); HILOGI("save SA:%{public}d,exId:%{public}d,n:%{public}zu", saId, static_cast(extraDataId), @@ -445,7 +445,7 @@ void CommonEventCollect::SaveSaExtraDataId(int32_t saId, int64_t extraDataId) void CommonEventCollect::RemoveSaExtraDataId(int64_t extraDataId) { - std::lock_guard autoLock(saExtraDataIdLock_); + std::lock_guard autoLock(saExtraDataIdLock_); HILOGD("rm saExtraId:%{public}d", static_cast(extraDataId)); auto iter = saExtraDataIdMap_.begin(); while (iter != saExtraDataIdMap_.end()) { @@ -467,7 +467,7 @@ void CommonEventCollect::RemoveSaExtraDataId(int64_t extraDataId) void CommonEventCollect::ClearSaExtraDataId(int32_t saId) { - std::lock_guard autoLock(saExtraDataIdLock_); + std::lock_guard autoLock(saExtraDataIdLock_); if (saExtraDataIdMap_.count(saId) == 0) { return; } @@ -481,7 +481,7 @@ int32_t CommonEventCollect::GetSaExtraDataIdList(int32_t saId, std::vector temp; { - std::lock_guard autoLock(saExtraDataIdLock_); + std::lock_guard autoLock(saExtraDataIdLock_); if (saExtraDataIdMap_.count(saId) == 0) { HILOGD("NF exId SA:%{public}d", saId); return ERR_OK; @@ -513,7 +513,7 @@ int32_t CommonEventCollect::GetSaExtraDataIdList(int32_t saId, std::vector CommonEventCollect::AddCommonEventName(const std::vector& events) { - std::lock_guard autoLock(commomEventLock_); + std::lock_guard autoLock(commomEventLock_); std::vector insertNames; for (auto& event : events) { auto iter = commonEventNames_.find(event.name); @@ -529,7 +529,7 @@ std::vector CommonEventCollect::AddCommonEventName(const std::vecto int32_t CommonEventCollect::AddCollectEvent(const std::vector& events) { - std::lock_guard autoLock(commonEventSubscriberLock_); + std::lock_guard autoLock(commonEventSubscriberLock_); auto insertNames = AddCommonEventName(events); if (insertNames.empty()) { return ERR_OK; @@ -545,7 +545,7 @@ int32_t CommonEventCollect::AddCollectEvent(const std::vector& ev int32_t CommonEventCollect::RemoveUnusedEvent(const OnDemandEvent& event) { - std::lock_guard autoLock(commomEventLock_); + std::lock_guard autoLock(commomEventLock_); auto iter = commonEventNames_.find(event.name); if (iter != commonEventNames_.end()) { HILOGI("CommonEventCollect remove event name: %{public}s", event.name.c_str()); diff --git a/services/samgr/native/source/collect/device_networking_collect.cpp b/services/samgr/native/source/collect/device_networking_collect.cpp index cc4e6c15699008b77726a23a0b69907df7c1a4e7..352f3cb78727a74d65477a1535677c53ddc98b21 100644 --- a/services/samgr/native/source/collect/device_networking_collect.cpp +++ b/services/samgr/native/source/collect/device_networking_collect.cpp @@ -197,7 +197,7 @@ void DeviceStateCallback::OnDeviceOnline(const DmDeviceInfo& deviceInfo) SystemAbilityManager::GetInstance()->InitDbinderService(); #endif { - lock_guard autoLock(deviceOnlineLock_); + lock_guard autoLock(deviceOnlineLock_); deviceOnlineSet_.emplace(deviceInfo.networkId); } @@ -214,7 +214,7 @@ void DeviceStateCallback::OnDeviceOffline(const DmDeviceInfo& deviceInfo) HILOGI("DeviceNetworkingCollect OnDeviceOffline size %{public}zu", deviceOnlineSet_.size()); bool isOffline = false; { - lock_guard autoLock(deviceOnlineLock_); + lock_guard autoLock(deviceOnlineLock_); deviceOnlineSet_.erase(deviceInfo.networkId); isOffline = deviceOnlineSet_.empty(); } @@ -232,19 +232,19 @@ void DeviceStateCallback::OnDeviceOffline(const DmDeviceInfo& deviceInfo) void DeviceStateCallback::ClearDeviceOnlineSet() { - lock_guard autoLock(deviceOnlineLock_); + lock_guard autoLock(deviceOnlineLock_); deviceOnlineSet_.clear(); } bool DeviceStateCallback::IsOnline() { - lock_guard autoLock(deviceOnlineLock_); + lock_guard autoLock(deviceOnlineLock_); return !deviceOnlineSet_.empty(); } void DeviceStateCallback::UpdateDeviceOnlineSet(const std::string& deviceId) { - lock_guard autoLock(deviceOnlineLock_); + lock_guard autoLock(deviceOnlineLock_); deviceOnlineSet_.emplace(deviceId); } diff --git a/services/samgr/native/source/collect/device_param_collect.cpp b/services/samgr/native/source/collect/device_param_collect.cpp index 4c52f0912fd8a1f5203fea9f51524372ba567415..36411862f3cffef54cddadfdc93eb005474e157f 100644 --- a/services/samgr/native/source/collect/device_param_collect.cpp +++ b/services/samgr/native/source/collect/device_param_collect.cpp @@ -52,7 +52,7 @@ bool DeviceParamCollect::CheckCondition(const OnDemandCondition& condition) void DeviceParamCollect::Init(const std::list& saProfiles) { - std::lock_guard autoLock(paramLock_); + std::lock_guard autoLock(paramLock_); HILOGI("DeviceParamCollect Init begin"); for (auto saProfile : saProfiles) { for (auto onDemandEvent : saProfile.startOnDemand.onDemandEvents) { @@ -89,7 +89,7 @@ int32_t DeviceParamCollect::OnStop() void DeviceParamCollect::WatchParameters() { - std::lock_guard autoLock(paramLock_); + std::lock_guard autoLock(paramLock_); for (auto param : pendingParams_) { HILOGD("DeviceParamCollect watch param: %{public}s", param.c_str()); int32_t result = WatchParameter(param.c_str(), DeviceParamCallback, this); @@ -104,7 +104,7 @@ void DeviceParamCollect::WatchParameters() int32_t DeviceParamCollect::AddCollectEvent(const std::vector& events) { - std::lock_guard autoLock(paramLock_); + std::lock_guard autoLock(paramLock_); for (auto& event : events) { auto iter = params_.find(event.name); if (iter != params_.end()) { @@ -123,7 +123,7 @@ int32_t DeviceParamCollect::AddCollectEvent(const std::vector& ev int32_t DeviceParamCollect::RemoveUnusedEvent(const OnDemandEvent& event) { - std::lock_guard autoLock(paramLock_); + std::lock_guard autoLock(paramLock_); auto iter = params_.find(event.name); if (iter != params_.end()) { int32_t result = RemoveParameterWatcher(event.name.c_str(), nullptr, nullptr); diff --git a/services/samgr/native/source/collect/device_status_collect_manager.cpp b/services/samgr/native/source/collect/device_status_collect_manager.cpp index 6ca3a0ff465e5383438b5782056d8f91410e2b33..cb72373369882ec47354a8517518d5138dd3ded1 100644 --- a/services/samgr/native/source/collect/device_status_collect_manager.cpp +++ b/services/samgr/native/source/collect/device_status_collect_manager.cpp @@ -78,7 +78,7 @@ void DeviceStatusCollectManager::RemoveWhiteCommonEvent() void DeviceStatusCollectManager::FilterOnDemandSaProfiles(const std::list& saProfiles) { - std::unique_lock writeLock(saProfilesLock_); + std::unique_lock writeLock(saProfilesLock_); for (auto& saProfile : saProfiles) { if (saProfile.startOnDemand.onDemandEvents.empty() && saProfile.stopOnDemand.onDemandEvents.empty()) { continue; @@ -129,7 +129,7 @@ void DeviceStatusCollectManager::GetSaControlListByPersistEvent(const OnDemandEv void DeviceStatusCollectManager::GetSaControlListByEvent(const OnDemandEvent& event, std::list& saControlList) { - std::shared_lock readLock(saProfilesLock_); + std::shared_lock readLock(saProfilesLock_); for (auto& profile : onDemandSaProfiles_) { // start on demand for (auto iterStart = profile.startOnDemandEvents.begin(); @@ -425,7 +425,7 @@ int32_t DeviceStatusCollectManager::GetOnDemandEvents(int32_t systemAbilityId, O std::vector& events) { HILOGI("GetOnDemandEvents begin"); - std::shared_lock readLock(saProfilesLock_); + std::shared_lock readLock(saProfilesLock_); auto iter = std::find_if(onDemandSaProfiles_.begin(), onDemandSaProfiles_.end(), [systemAbilityId](auto saProfile) { return saProfile.saId == systemAbilityId; }); @@ -565,7 +565,7 @@ int32_t DeviceStatusCollectManager::UpdateOnDemandEvents(int32_t systemAbilityId { HILOGI("UpdateOnDemandEvents begin saId:%{public}d, type:%{public}d", systemAbilityId, type); std::vector oldEvents; - std::unique_lock writeLock(saProfilesLock_); + std::unique_lock writeLock(saProfilesLock_); auto iter = std::find_if(onDemandSaProfiles_.begin(), onDemandSaProfiles_.end(), [systemAbilityId](auto saProfile) { return saProfile.saId == systemAbilityId; diff --git a/services/samgr/native/source/collect/device_switch_collect.cpp b/services/samgr/native/source/collect/device_switch_collect.cpp index 976690d3f714cbbf61129a332ee43501f9f89d18..53bd9f0caca68a2863b895433fe530bc672c06c2 100644 --- a/services/samgr/native/source/collect/device_switch_collect.cpp +++ b/services/samgr/native/source/collect/device_switch_collect.cpp @@ -157,7 +157,7 @@ void CesStateListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std: int32_t SwitchEventSubscriber::SubscribeSwitchEvent() { HILOGI("DeviceSwitchCollect Subscribe Switch State"); - std::lock_guard autoLock(isListenEventLock_); + std::lock_guard autoLock(isListenEventLock_); if (isListenSwitchEvent_) { return ERR_OK; } @@ -171,7 +171,7 @@ int32_t SwitchEventSubscriber::SubscribeSwitchEvent() int32_t SwitchEventSubscriber::UnSubscribeSwitchEvent() { HILOGI("DeviceSwitchCollect UnSubscribe Switch State"); - std::lock_guard autoLock(isListenEventLock_); + std::lock_guard autoLock(isListenEventLock_); if (!isListenSwitchEvent_) { return ERR_OK; } diff --git a/services/samgr/native/source/collect/device_timed_collect.cpp b/services/samgr/native/source/collect/device_timed_collect.cpp index a2a892e8c3dfd6169d5d867ecac98188c7656dd9..f63c4495570f062a1c2ec99ec7a5db6c67db6eac 100644 --- a/services/samgr/native/source/collect/device_timed_collect.cpp +++ b/services/samgr/native/source/collect/device_timed_collect.cpp @@ -101,7 +101,7 @@ void DeviceTimedCollect::ProcessPersistenceLoopTask(int64_t disTime, int64_t tri { int64_t interval = atoi(strInterval.c_str()); { - lock_guard autoLock(persitenceLoopEventSetLock_); + lock_guard autoLock(persitenceLoopEventSetLock_); if (persitenceLoopTasks_.count(interval) > 0) { return; } @@ -118,7 +118,7 @@ void DeviceTimedCollect::ProcessPersistenceLoopTask(int64_t disTime, int64_t tri return; } auto task = [this, interval] () { - lock_guard autoLock(persitenceLoopEventSetLock_); + lock_guard autoLock(persitenceLoopEventSetLock_); if (persitenceLoopTasks_.find(interval) != persitenceLoopTasks_.end()) { HILOGI("DeviceTimedCollect Persistence ReportEvent interval: %{public}" PRId64, interval); ReportEventByTimeInfo(interval, true); @@ -128,7 +128,7 @@ void DeviceTimedCollect::ProcessPersistenceLoopTask(int64_t disTime, int64_t tri } }; { - lock_guard autoLock(persitenceLoopEventSetLock_); + lock_guard autoLock(persitenceLoopEventSetLock_); persitenceLoopTasks_[interval] = task; } if (disTime <= 0) { @@ -143,7 +143,7 @@ void DeviceTimedCollect::ProcessPersistenceLoopTask(int64_t disTime, int64_t tri void DeviceTimedCollect::ReportEventByTimeInfo(int32_t interval, bool persistence) { - lock_guard autoLock(timeInfosLock_); + lock_guard autoLock(timeInfosLock_); if (timeInfos_.count(interval) == 0) { return; } @@ -161,7 +161,7 @@ void DeviceTimedCollect::ReportEventByTimeInfo(int32_t interval, bool persistenc void DeviceTimedCollect::SaveTimedInfos(const OnDemandEvent& onDemandEvent, int32_t interval) { - lock_guard autoLock(timeInfosLock_); + lock_guard autoLock(timeInfosLock_); if (timeInfos_.count(interval) == 0) { TimeInfo info; timeInfos_[interval] = info; @@ -191,10 +191,10 @@ void DeviceTimedCollect::SaveTimedEvent(const OnDemandEvent& onDemandEvent) return; } if (onDemandEvent.persistence) { - lock_guard autoLock(persitenceLoopEventSetLock_); + lock_guard autoLock(persitenceLoopEventSetLock_); persitenceLoopEventSet_.insert(interval); } else { - lock_guard autoLock(nonPersitenceLoopEventSetLock_); + lock_guard autoLock(nonPersitenceLoopEventSetLock_); nonPersitenceLoopEventSet_.insert(interval); } SaveTimedInfos(onDemandEvent, interval); @@ -207,7 +207,7 @@ void DeviceTimedCollect::PostPersistenceLoopTaskLocked(int32_t interval) return; } persitenceLoopTasks_[interval] = [this, interval] () { - lock_guard autoLock(persitenceLoopEventSetLock_); + lock_guard autoLock(persitenceLoopEventSetLock_); if (persitenceLoopTasks_.find(interval) != persitenceLoopTasks_.end()) { HILOGI("DeviceTimedCollect PostPersistence ReportEvent interval: %{public}d", interval); ReportEventByTimeInfo(interval, true); @@ -226,7 +226,7 @@ void DeviceTimedCollect::PostNonPersistenceLoopTaskLocked(int32_t interval) return; } nonPersitenceLoopTasks_[interval] = [this, interval] () { - lock_guard autoLock(nonPersitenceLoopEventSetLock_); + lock_guard autoLock(nonPersitenceLoopEventSetLock_); if (nonPersitenceLoopEventSet_.find(interval) != nonPersitenceLoopEventSet_.end()) { HILOGI("DeviceTimedCollect ReportEvent interval: %{public}d", interval); ReportEventByTimeInfo(interval, false); @@ -241,7 +241,7 @@ void DeviceTimedCollect::PostNonPersistenceLoopTaskLocked(int32_t interval) void DeviceTimedCollect::PostDelayTaskByTimeInfo(std::function callback, int32_t interval, int32_t disTime) { - lock_guard autoLock(timeInfosLock_); + lock_guard autoLock(timeInfosLock_); if (timeInfos_.count(interval) == 0) { return; } @@ -277,7 +277,7 @@ int32_t DeviceTimedCollect::OnStart() void DeviceTimedCollect::PostNonPersistenceLoopTasks() { - lock_guard autoLock(nonPersitenceLoopEventSetLock_); + lock_guard autoLock(nonPersitenceLoopEventSetLock_); for (auto it = nonPersitenceLoopEventSet_.begin(); it != nonPersitenceLoopEventSet_.end(); ++it) { HILOGI("DeviceTimedCollect send task: %{public}d", *it); PostNonPersistenceLoopTaskLocked(*it); @@ -286,7 +286,7 @@ void DeviceTimedCollect::PostNonPersistenceLoopTasks() void DeviceTimedCollect::PostPersistenceLoopTasks() { - lock_guard autoLock(persitenceLoopEventSetLock_); + lock_guard autoLock(persitenceLoopEventSetLock_); for (auto it = persitenceLoopEventSet_.begin(); it != persitenceLoopEventSet_.end(); ++it) { HILOGI("DeviceTimedCollect send persitence task: %{public}d", *it); PostPersistenceLoopTaskLocked(*it); @@ -355,12 +355,12 @@ int32_t DeviceTimedCollect::AddCollectEvent(const std::vector& ev int64_t timeGap = CalculateDelayTime(event.value); #ifdef PREFERENCES_ENABLE if (event.persistence) { - std::lock_guard autoLock(persitenceTimedEventSetLock_); + std::lock_guard autoLock(persitenceTimedEventSetLock_); PostPersistenceTimedTaskLocked(event.value, timeGap); continue; } #endif - std::lock_guard autoLock(nonPersitenceTimedEventSetLock); + std::lock_guard autoLock(nonPersitenceTimedEventSetLock); PostNonPersistenceTimedTaskLocked(event.value, timeGap); continue; } @@ -378,7 +378,7 @@ int32_t DeviceTimedCollect::AddCollectEvent(const std::vector& ev return ERR_INVALID_VALUE; } SaveTimedInfos(event, interval); - std::lock_guard autoLock(nonPersitenceLoopEventSetLock_); + std::lock_guard autoLock(nonPersitenceLoopEventSetLock_); auto iter = nonPersitenceLoopEventSet_.find(interval); if (iter != nonPersitenceLoopEventSet_.end()) { continue; @@ -408,7 +408,7 @@ int32_t DeviceTimedCollect::RemoveUnusedEvent(const OnDemandEvent& event) void DeviceTimedCollect::RemoveTimesInfo(const OnDemandEvent& onDemandEvent, int32_t interval) { - lock_guard autoLock(timeInfosLock_); + lock_guard autoLock(timeInfosLock_); if (timeInfos_.count(interval) == 0) { return; } @@ -427,7 +427,7 @@ void DeviceTimedCollect::RemoveTimesInfo(const OnDemandEvent& onDemandEvent, int void DeviceTimedCollect::RemoveNonPersistenceLoopTask(int32_t interval) { - std::lock_guard autoLock(nonPersitenceLoopEventSetLock_); + std::lock_guard autoLock(nonPersitenceLoopEventSetLock_); auto iter = nonPersitenceLoopEventSet_.find(interval); if (iter != nonPersitenceLoopEventSet_.end()) { nonPersitenceLoopEventSet_.erase(iter); @@ -437,7 +437,7 @@ void DeviceTimedCollect::RemoveNonPersistenceLoopTask(int32_t interval) void DeviceTimedCollect::RemovePersistenceLoopTask(int32_t interval) { - std::lock_guard autoLock(persitenceLoopEventSetLock_); + std::lock_guard autoLock(persitenceLoopEventSetLock_); auto iter = persitenceLoopEventSet_.find(interval); if (iter != persitenceLoopEventSet_.end()) { persitenceLoopEventSet_.erase(iter); diff --git a/services/samgr/native/source/ffrt_handler.cpp b/services/samgr/native/source/ffrt_handler.cpp index e08110b8fd89ad3221a2effd025cc787cc7c69db..722bd94711f7afc3369e3d3b63975893cb72d1ff 100644 --- a/services/samgr/native/source/ffrt_handler.cpp +++ b/services/samgr/native/source/ffrt_handler.cpp @@ -33,6 +33,7 @@ FFRTHandler::FFRTHandler(const std::string& name) void FFRTHandler::CleanFfrt() { + std::unique_lock lock(mutex_); for (auto iter = taskMap_.begin(); iter != taskMap_.end(); ++iter) { HILOGI("CleanFfrt taskMap_ %{public}s", iter->first.c_str()); if (queue_ != nullptr && iter->second != nullptr) { @@ -51,6 +52,7 @@ void FFRTHandler::CleanFfrt() void FFRTHandler::SetFfrt(const std::string& name) { + std::unique_lock lock(mutex_); queue_ = std::make_shared(name.c_str()); } @@ -96,7 +98,7 @@ bool FFRTHandler::PostTask(std::function func, const std::string& name, HILOGE("invalid delay time"); return false; } - std::unique_lock lock(mutex_); + std::unique_lock lock(mutex_); task_handle handler = queue_->submit_h(func, task_attr().delay(delayTime * CONVERSION_FACTOR)); if (handler == nullptr) { HILOGE("FFRTHandler post task failed"); @@ -108,7 +110,7 @@ bool FFRTHandler::PostTask(std::function func, const std::string& name, void FFRTHandler::RemoveTask(const std::string& name) { - std::unique_lock lock(mutex_); + std::unique_lock lock(mutex_); auto item = taskMap_.find(name); if (item == taskMap_.end()) { HILOGW("rm task %{public}s NF", name.c_str()); @@ -125,7 +127,7 @@ void FFRTHandler::RemoveTask(const std::string& name) void FFRTHandler::DelTask(const std::string& name) { - std::unique_lock lock(mutex_); + std::unique_lock lock(mutex_); auto item = taskMap_.find(name); if (item == taskMap_.end()) { HILOGW("del task %{public}s NF", name.c_str()); @@ -137,7 +139,7 @@ void FFRTHandler::DelTask(const std::string& name) bool FFRTHandler::HasInnerEvent(const std::string name) { - std::unique_lock lock(mutex_); + std::unique_lock lock(mutex_); auto item = taskMap_.find(name); if (item == taskMap_.end()) { return false; diff --git a/services/samgr/native/source/samgr_time_handler.cpp b/services/samgr/native/source/samgr_time_handler.cpp index db5ed262c4551b4556236e72e6017ca1c06dc752..048e91277df18b40a04b3cfe8f054f839b774a41 100644 --- a/services/samgr/native/source/samgr_time_handler.cpp +++ b/services/samgr/native/source/samgr_time_handler.cpp @@ -26,12 +26,12 @@ constexpr int32_t RETRY_TIMES = 3; } SamgrTimeHandler* volatile SamgrTimeHandler::singleton = nullptr; SamgrTimeHandler::Deletor SamgrTimeHandler::deletor; -static mutex mtx; +static samgr::mutex mtx; SamgrTimeHandler* SamgrTimeHandler::GetInstance() { if (singleton == nullptr) { - lock_guard autoLock(mtx); + lock_guard autoLock(mtx); if (singleton == nullptr) { singleton = new SamgrTimeHandler; } diff --git a/services/samgr/native/source/schedule/system_ability_state_machine.cpp b/services/samgr/native/source/schedule/system_ability_state_machine.cpp index e8dc6bf6ea23edfd9062c6b965ca058dc668e4f8..c57625d24617e517bbbb28ee85ba7515e03dd1ff 100644 --- a/services/samgr/native/source/schedule/system_ability_state_machine.cpp +++ b/services/samgr/native/source/schedule/system_ability_state_machine.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#include - #include "datetime_ex.h" #include "sam_log.h" #include "string_ex.h" @@ -85,7 +83,7 @@ bool SystemAbilityStateMachine::UpdateStateCount(const std::shared_ptr autoLock(context->stateCountLock); + std::lock_guard autoLock(context->stateCountLock); if (!context->abilityStateCountMap.count(fromState) || !context->abilityStateCountMap.count(toState)) { HILOGE("Scheduler proc:%{public}s invalid state", Str16ToStr8(context->processName).c_str()); diff --git a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp index eb77d83f9383c751e0ced094cf47f8ce1f2ca744..376fa54aafec423b74a84c42fe0e44104cfad5a8 100644 --- a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp +++ b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp @@ -93,7 +93,7 @@ void SystemAbilityStateScheduler::SetFfrt() void SystemAbilityStateScheduler::CleanResource() { - std::unique_lock abiltyWriteLock(abiltyMapLock_); + std::unique_lock abiltyWriteLock(abiltyMapLock_); HILOGI("Scheduler CleanResource"); abilityContextMap_.clear(); } @@ -104,7 +104,7 @@ void SystemAbilityStateScheduler::InitStateContext(const std::list& s if (saProfile.process.empty()) { continue; } - std::unique_lock processWriteLock(processMapLock_); + std::unique_lock processWriteLock(processMapLock_); if (processContextMap_.count(saProfile.process) == 0) { auto processContext = std::make_shared(); processContext->processName = saProfile.process; @@ -123,7 +123,7 @@ void SystemAbilityStateScheduler::InitStateContext(const std::list& s int32_t delayUnloadTime = LimitDelayUnloadTime(saProfile.stopOnDemand.delayTime); abilityContext->delayUnloadTime = delayUnloadTime; abilityContext->ownProcessContext = processContextMap_[saProfile.process]; - std::unique_lock abiltyWriteLock(abiltyMapLock_); + std::unique_lock abiltyWriteLock(abiltyMapLock_); abilityContextMap_[saProfile.saId] = abilityContext; } } @@ -148,7 +148,7 @@ void SystemAbilityStateScheduler::InitSamgrProcessContext() abilityContext->isAutoRestart = false; abilityContext->delayUnloadTime = MAX_DELAY_TIME; abilityContext->ownProcessContext = processContextMap_[SAMGR_PROCESS_NAME]; - std::unique_lock abiltyWriteLock(abiltyMapLock_); + std::unique_lock abiltyWriteLock(abiltyMapLock_); abilityContextMap_[0] = abilityContext; } @@ -166,7 +166,7 @@ int32_t SystemAbilityStateScheduler::LimitDelayUnloadTime(int32_t delayUnloadTim bool SystemAbilityStateScheduler::GetSystemAbilityContext(int32_t systemAbilityId, std::shared_ptr& abilityContext) { - std::shared_lock readLock(abiltyMapLock_); + std::shared_lock readLock(abiltyMapLock_); if (abilityContextMap_.count(systemAbilityId) == 0) { HILOGD("Scheduler SA:%{public}d not in SA profiles", systemAbilityId); return false; @@ -204,7 +204,7 @@ void SystemAbilityStateScheduler::UpdateLimitDelayUnloadTimeTask(int32_t systemA if (!GetSystemAbilityContext(systemAbilityId, abilityContext)) { return; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); if (abilityContext->lastStartTime != 0) { int64_t begin = abilityContext->lastStartTime; int64_t end = GetTickCount(); @@ -221,7 +221,7 @@ void SystemAbilityStateScheduler::UpdateLimitDelayUnloadTimeTask(int32_t systemA bool SystemAbilityStateScheduler::GetSystemProcessContext(const std::u16string& processName, std::shared_ptr& processContext) { - std::shared_lock readLock(processMapLock_); + std::shared_lock readLock(processMapLock_); if (processContextMap_.count(processName) == 0) { HILOGE("Scheduler proc:%{public}s invalid", Str16ToStr8(processName).c_str()); return false; @@ -240,7 +240,7 @@ bool SystemAbilityStateScheduler::IsSystemAbilityUnloading(int32_t systemAbility if (!GetSystemAbilityContext(systemAbilityId, abilityContext)) { return false; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); if (abilityContext->state ==SystemAbilityState::UNLOADING || abilityContext->ownProcessContext->state == SystemProcessState::STOPPING) { return true; @@ -255,7 +255,7 @@ int32_t SystemAbilityStateScheduler::HandleLoadAbilityEvent(int32_t systemAbilit isExist = false; return ERR_INVALID_VALUE; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); if (abilityContext->ownProcessContext->state == SystemProcessState::NOT_STARTED) { isExist = false; return ERR_INVALID_VALUE; @@ -282,7 +282,7 @@ int32_t SystemAbilityStateScheduler::HandleLoadAbilityEvent(const LoadRequestInf HILOGI("Scheduler SA:%{public}d load start %{public}d,%{public}d_" "%{public}d_%{public}d", loadRequestInfo.systemAbilityId, loadRequestInfo.callingPid, loadRequestInfo.loadEvent.eventId, abilityContext->ownProcessContext->state, abilityContext->state); - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); int32_t result = HandleLoadAbilityEventLocked(abilityContext, loadRequestInfo); if (result != ERR_OK) { HILOGE("Scheduler SA:%{public}d handle load fail,ret:%{public}d", @@ -345,7 +345,7 @@ int32_t SystemAbilityStateScheduler::HandleUnloadAbilityEvent( HILOGI("Scheduler SA:%{public}d unload start %{public}d,%{public}d_" "%{public}d_%{public}d", unloadRequestInfo->systemAbilityId, unloadRequestInfo->callingPid, unloadRequestInfo->unloadEvent.eventId, abilityContext->ownProcessContext->state, abilityContext->state); - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); int32_t result = HandleUnloadAbilityEventLocked(abilityContext, unloadRequestInfo); if (result != ERR_OK) { HILOGE("Scheduler SA:%{public}d handle unload fail,ret:%{public}d", @@ -398,7 +398,7 @@ int32_t SystemAbilityStateScheduler::HandleCancelUnloadAbilityEvent(int32_t syst activeReason[KEY_VALUE] = ""; activeReason[KEY_EXTRA_DATA_ID] = -1; int32_t result = ERR_INVALID_VALUE; - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); switch (abilityContext->state) { case SystemAbilityState::UNLOADABLE: result = ActiveSystemAbilityLocked(abilityContext, activeReason); @@ -432,7 +432,7 @@ int32_t SystemAbilityStateScheduler::SendAbilityStateEvent(int32_t systemAbility if (!GetSystemAbilityContext(systemAbilityId, abilityContext)) { return ERR_INVALID_VALUE; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); return stateEventHandler_->HandleAbilityEventLocked(abilityContext, event); } @@ -444,7 +444,7 @@ int32_t SystemAbilityStateScheduler::SendProcessStateEvent(const ProcessInfo& pr if (!GetSystemProcessContext(processInfo.processName, processContext)) { return ERR_INVALID_VALUE; } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); return stateEventHandler_->HandleProcessEventLocked(processContext, processInfo, event); } @@ -589,7 +589,7 @@ int32_t SystemAbilityStateScheduler::TryUnloadAllSystemAbility( HILOGE("Scheduler:proc context is null"); return ERR_INVALID_VALUE; } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (CanUnloadAllSystemAbilityLocked(processContext, true)) { return UnloadAllSystemAbilityLocked(processContext); } @@ -599,7 +599,7 @@ int32_t SystemAbilityStateScheduler::TryUnloadAllSystemAbility( bool SystemAbilityStateScheduler::CanUnloadAllSystemAbility( const std::shared_ptr& processContext) { - std::lock_guard autoLock(processContext->stateCountLock); + std::lock_guard autoLock(processContext->stateCountLock); return CanUnloadAllSystemAbilityLocked(processContext, true); } @@ -676,7 +676,7 @@ int32_t SystemAbilityStateScheduler::PostUnloadTimeoutTask(const std::shared_ptr } else { HILOGE("TimeoutTask processHandler_ is null"); } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (processContext->state == SystemProcessState::STOPPING) { HILOGW("Scheduler proc:%{public}s unload SA timeout", Str16ToStr8(processContext->processName).c_str()); @@ -767,7 +767,7 @@ int32_t SystemAbilityStateScheduler::UnloadProcess(const std::vector readLock(processMapLock_); + std::shared_lock readLock(processMapLock_); for (const auto& it : processList) { if (processContextMap_.count(it) != 0) { auto& processContext = processContextMap_[it]; @@ -776,7 +776,7 @@ int32_t SystemAbilityStateScheduler::UnloadProcess(const std::vector autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (CanUnloadAllSystemAbilityLocked(processContext)) { ret = UnloadAllSystemAbilityLocked(processContext); } @@ -794,7 +794,7 @@ int32_t SystemAbilityStateScheduler::UnloadAllIdleSystemAbility() { HILOGI("Scheduler:UnloadAllIdleSa"); int32_t result = ERR_OK; - std::shared_lock readLock(processMapLock_); + std::shared_lock readLock(processMapLock_); for (auto it : processContextMap_) { auto& processContext = it.second; if (processContext == nullptr) { @@ -802,7 +802,7 @@ int32_t SystemAbilityStateScheduler::UnloadAllIdleSystemAbility() } int32_t ret = ERR_OK; - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (CanUnloadAllSystemAbilityLocked(processContext)) { ret = UnloadAllSystemAbilityLocked(processContext); } @@ -822,7 +822,7 @@ int32_t SystemAbilityStateScheduler::TryKillSystemProcess( HILOGE("Scheduler:proc context is null"); return ERR_INVALID_VALUE; } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (CanKillSystemProcessLocked(processContext)) { return KillSystemProcessLocked(processContext); } @@ -832,7 +832,7 @@ int32_t SystemAbilityStateScheduler::TryKillSystemProcess( bool SystemAbilityStateScheduler::CanKillSystemProcess( const std::shared_ptr& processContext) { - std::lock_guard autoLock(processContext->stateCountLock); + std::lock_guard autoLock(processContext->stateCountLock); return CanKillSystemProcessLocked(processContext); } @@ -954,7 +954,7 @@ int32_t SystemAbilityStateScheduler::HandleAbnormallyDiedAbilityLocked( void SystemAbilityStateScheduler::NotifyProcessStarted(const std::shared_ptr& processContext) { - std::shared_lock readLock(listenerSetLock_); + std::shared_lock readLock(listenerSetLock_); for (auto& listener : processListeners_) { if (listener->AsObject() != nullptr) { SystemProcessInfo systemProcessInfo = {Str16ToStr8(processContext->processName), processContext->pid, @@ -966,7 +966,7 @@ void SystemAbilityStateScheduler::NotifyProcessStarted(const std::shared_ptr& processContext) { - std::shared_lock readLock(listenerSetLock_); + std::shared_lock readLock(listenerSetLock_); for (auto& listener : processListeners_) { if (listener->AsObject() != nullptr) { SystemProcessInfo systemProcessInfo = {Str16ToStr8(processContext->processName), processContext->pid, @@ -1065,7 +1065,7 @@ int32_t SystemAbilityStateScheduler::GetSystemProcessInfo(int32_t systemAbilityI return ERR_INVALID_VALUE; } std::shared_ptr processContext = abilityContext->ownProcessContext; - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); systemProcessInfo = {Str16ToStr8(processContext->processName), processContext->pid, processContext->uid}; return ERR_OK; @@ -1074,13 +1074,13 @@ int32_t SystemAbilityStateScheduler::GetSystemProcessInfo(int32_t systemAbilityI int32_t SystemAbilityStateScheduler::GetRunningSystemProcess(std::list& systemProcessInfos) { HILOGI("Scheduler:get running process"); - std::shared_lock readLock(processMapLock_); + std::shared_lock readLock(processMapLock_); for (auto it : processContextMap_) { auto& processContext = it.second; if (processContext == nullptr) { continue; } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (processContext->state == SystemProcessState::STARTED) { SystemProcessInfo systemProcessInfo = {Str16ToStr8(processContext->processName), processContext->pid, processContext->uid}; @@ -1093,13 +1093,13 @@ int32_t SystemAbilityStateScheduler::GetRunningSystemProcess(std::list readLock(processMapLock_); + std::shared_lock readLock(processMapLock_); for (auto it : processContextMap_) { auto& processContext = it.second; if (processContext == nullptr) { continue; } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); if (processContext->pid == pid) { processName = processContext->processName; return ERR_OK; @@ -1110,7 +1110,7 @@ int32_t SystemAbilityStateScheduler::GetProcessNameByProcessId(int32_t pid, std: void SystemAbilityStateScheduler::GetAllSystemAbilityInfo(std::string& result) { - std::shared_lock readLock(abiltyMapLock_); + std::shared_lock readLock(abiltyMapLock_); for (auto it : abilityContextMap_) { if (it.second == nullptr) { continue; @@ -1124,7 +1124,7 @@ void SystemAbilityStateScheduler::GetAllSystemAbilityInfo(std::string& result) result += "sa_pending_event: "; result += PENDINGEVENT_ENUM_STR[static_cast(it.second->pendingEvent)]; if (it.second->ownProcessContext != nullptr) { - std::lock_guard autoLock(it.second->ownProcessContext->stateCountLock); + std::lock_guard autoLock(it.second->ownProcessContext->stateCountLock); result += '\n'; result += "process_name: "; result += Str16ToStr8(it.second->ownProcessContext->processName); @@ -1146,7 +1146,7 @@ void SystemAbilityStateScheduler::GetSystemAbilityInfo(int32_t said, std::string result.append("said is not exist"); return; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); result += "said: "; result += std::to_string(said); result += "\n"; @@ -1174,7 +1174,7 @@ void SystemAbilityStateScheduler::GetProcessInfo(const std::string& processName, result.append("process is not exist"); return; } - std::lock_guard autoLock(processContext->processLock); + std::lock_guard autoLock(processContext->processLock); result += "process_name: "; result += Str16ToStr8(processContext->processName); result += "\n"; @@ -1204,7 +1204,7 @@ void SystemAbilityStateScheduler::GetProcessInfo(const std::string& processName, void SystemAbilityStateScheduler::GetAllSystemAbilityInfoByState(const std::string& state, std::string& result) { - std::shared_lock readLock(abiltyMapLock_); + std::shared_lock readLock(abiltyMapLock_); for (auto it : abilityContextMap_) { if (it.second == nullptr || SA_STATE_ENUM_STR[static_cast(it.second->state)] != state) { continue; @@ -1218,7 +1218,7 @@ void SystemAbilityStateScheduler::GetAllSystemAbilityInfoByState(const std::stri result += "sa_pending_event: "; result += PENDINGEVENT_ENUM_STR[static_cast(it.second->pendingEvent)]; if (it.second->ownProcessContext != nullptr) { - std::lock_guard autoLock(it.second->ownProcessContext->stateCountLock); + std::lock_guard autoLock(it.second->ownProcessContext->stateCountLock); result += '\n'; result += "process_name: "; result += Str16ToStr8(it.second->ownProcessContext->processName); @@ -1235,7 +1235,7 @@ void SystemAbilityStateScheduler::GetAllSystemAbilityInfoByState(const std::stri int32_t SystemAbilityStateScheduler::SubscribeSystemProcess(const sptr& listener) { - std::unique_lock writeLock(listenerSetLock_); + std::unique_lock writeLock(listenerSetLock_); auto iter = std::find_if(processListeners_.begin(), processListeners_.end(), [listener](sptr& item) { return item->AsObject() == listener->AsObject(); @@ -1254,7 +1254,7 @@ int32_t SystemAbilityStateScheduler::SubscribeSystemProcess(const sptr& listener) { - std::unique_lock writeLock(listenerSetLock_); + std::unique_lock writeLock(listenerSetLock_); auto iter = std::find_if(processListeners_.begin(), processListeners_.end(), [listener](sptr& item) { return item->AsObject() == listener->AsObject(); @@ -1286,7 +1286,7 @@ int32_t SystemAbilityStateScheduler::ProcessDelayUnloadEvent(int32_t systemAbili if (!GetSystemAbilityContext(systemAbilityId, abilityContext)) { return GET_SA_CONTEXT_FAIL; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); return ProcessDelayUnloadEventLocked(systemAbilityId); } @@ -1354,7 +1354,7 @@ int32_t SystemAbilityStateScheduler::CheckStartEnableOnce(const OnDemandEvent& e { int32_t result = ERR_INVALID_VALUE; if (saControl.enableOnce) { - std::lock_guard autoLock(startEnableOnceLock_); + std::lock_guard autoLock(startEnableOnceLock_); auto iter = startEnableOnceMap_.find(saControl.saId); if (iter != startEnableOnceMap_.end() && SamgrUtil::IsSameEvent(event, startEnableOnceMap_[saControl.saId])) { HILOGI("ondemand canceled for enable-once, ondemandId:%{public}d, SA:%{public}d", @@ -1369,7 +1369,7 @@ int32_t SystemAbilityStateScheduler::CheckStartEnableOnce(const OnDemandEvent& e LoadRequestInfo loadRequestInfo = {LOCAL_DEVICE, callback, saControl.saId, callingPid, event}; result = HandleLoadAbilityEvent(loadRequestInfo); if (saControl.enableOnce && result != ERR_OK) { - std::lock_guard autoLock(startEnableOnceLock_); + std::lock_guard autoLock(startEnableOnceLock_); auto& events = startEnableOnceMap_[saControl.saId]; events.remove(event); if (events.empty()) { @@ -1390,7 +1390,7 @@ int32_t SystemAbilityStateScheduler::CheckStopEnableOnce(const OnDemandEvent& ev { int32_t result = ERR_INVALID_VALUE; if (saControl.enableOnce) { - std::lock_guard autoLock(stopEnableOnceLock_); + std::lock_guard autoLock(stopEnableOnceLock_); auto iter = stopEnableOnceMap_.find(saControl.saId); if (iter != stopEnableOnceMap_.end() && SamgrUtil::IsSameEvent(event, stopEnableOnceMap_[saControl.saId])) { HILOGI("ondemand canceled for enable-once, ondemandId:%{public}d, SA:%{public}d", @@ -1406,7 +1406,7 @@ int32_t SystemAbilityStateScheduler::CheckStopEnableOnce(const OnDemandEvent& ev std::make_shared(event, saControl.saId, callingPid); result = HandleUnloadAbilityEvent(unloadRequestInfo); if (saControl.enableOnce && result != ERR_OK) { - std::lock_guard autoLock(stopEnableOnceLock_); + std::lock_guard autoLock(stopEnableOnceLock_); auto& events = stopEnableOnceMap_[saControl.saId]; events.remove(event); if (events.empty()) { @@ -1428,7 +1428,7 @@ int64_t SystemAbilityStateScheduler::GetSystemAbilityIdleTime(int32_t systemAbil if (!GetSystemAbilityContext(systemAbilityId, abilityContext)) { return -1; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); return abilityContext->lastIdleTime; } @@ -1439,7 +1439,7 @@ bool SystemAbilityStateScheduler::GetLruIdleSystemAbilityInfo(int32_t systemAbil if (!GetSystemAbilityContext(systemAbilityId, abilityContext)) { return false; } - std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); + std::lock_guard autoLock(abilityContext->ownProcessContext->processLock); processName = abilityContext->ownProcessContext->processName; pid = abilityContext->ownProcessContext->pid; lastStopTime = abilityContext->ownProcessContext->lastStopTime; diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index b3bfe1d260390e9bfe639e0ec401ef2272404e18..f092a8591c9c848578983027c4eee5193dec9cb3 100644 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -87,14 +87,14 @@ constexpr int32_t FIRST_DUMP_INDEX = 0; constexpr int64_t TWO_MINUTES_SECONDS = 120 * 1000; // ms } -std::mutex SystemAbilityManager::instanceLock; +samgr::mutex SystemAbilityManager::instanceLock; sptr SystemAbilityManager::instance; void SystemAbilityManager::RegisterDistribute(int32_t systemAbilityId, bool isDistributed) { #ifdef SAMGR_ENABLE_DELAY_DBINDER if (isDistributed) { - std::shared_lock readLock(dBinderServiceLock_); + std::shared_lock readLock(dBinderServiceLock_); if (dBinderService_ != nullptr) { u16string strName = Str8ToStr16(to_string(systemAbilityId)); dBinderService_->RegisterRemoteProxy(strName, systemAbilityId); @@ -106,7 +106,7 @@ void SystemAbilityManager::RegisterDistribute(int32_t systemAbilityId, bool isDi } } if (systemAbilityId == SOFTBUS_SERVER_SA_ID) { - std::shared_lock readLock(dBinderServiceLock_); + std::shared_lock readLock(dBinderServiceLock_); if (dBinderService_ != nullptr && rpcCallbackImp_ != nullptr) { bool ret = dBinderService_->StartDBinderService(rpcCallbackImp_); HILOGI("start result is %{public}s", ret ? "succeed" : "fail"); @@ -130,7 +130,7 @@ void SystemAbilityManager::RegisterDistribute(int32_t systemAbilityId, bool isDi #ifdef SAMGR_ENABLE_DELAY_DBINDER void SystemAbilityManager::InitDbinderService() { - std::unique_lock writeLock(dBinderServiceLock_); + std::unique_lock writeLock(dBinderServiceLock_); if (!isDbinderServiceInit_) { dBinderService_ = DBinderService::GetInstance(); rpcCallbackImp_ = make_shared(); @@ -213,7 +213,7 @@ bool SystemAbilityManager::IpcStatSamgrProc(int32_t fd, int32_t cmd) void SystemAbilityManager::IpcDumpAllProcess(int32_t fd, int32_t cmd) { - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); for (auto iter = systemProcessMap_.begin(); iter != systemProcessMap_.end(); iter++) { sptr obj = iface_cast(iter->second); if (obj != nullptr) { @@ -271,7 +271,7 @@ int32_t SystemAbilityManager::Dump(int32_t fd, const std::vector if ((argsWithStr8.size() > 0) && (argsWithStr8[FIRST_DUMP_INDEX] == ARGS_LISTENER_PARAM)) { std::map> dumpListeners; { - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); dumpListeners = listenerMap_; } return SystemAbilityManagerDumper::ListenerDumpProc(dumpListeners, fd, argsWithStr8); @@ -291,7 +291,7 @@ int32_t SystemAbilityManager::Dump(int32_t fd, const std::vector void SystemAbilityManager::AddSamgrToAbilityMap() { - unique_lock writeLock(abilityMapLock_); + unique_lock writeLock(abilityMapLock_); int32_t systemAbilityId = 0; SAInfo saInfo; saInfo.remoteObj = this; @@ -335,7 +335,7 @@ void SystemAbilityManager::InitSaProfile() if (collectManager_ != nullptr) { collectManager_->Init(saInfos); } - lock_guard autoLock(saProfileMapLock_); + lock_guard autoLock(saProfileMapLock_); onDemandSaIdsSet_.insert(DEVICE_INFO_SERVICE_SA); onDemandSaIdsSet_.insert(HIDUMPER_SERVICE_SA); onDemandSaIdsSet_.insert(MEDIA_ANALYSIS_SERVICE_SA); @@ -377,9 +377,9 @@ std::list SystemAbilityManager::GetAllOndemandSa() { std::list ondemandSaids; { - lock_guard autoLock(saProfileMapLock_); + lock_guard autoLock(saProfileMapLock_); for (const auto& [said, value] : saProfileMap_) { - shared_lock readLock(abilityMapLock_); + shared_lock readLock(abilityMapLock_); auto iter = abilityMap_.find(said); if (iter == abilityMap_.end()) { ondemandSaids.emplace_back(said); @@ -509,7 +509,7 @@ sptr SystemAbilityManager::GetSystemAbilityFromRemote(int32_t sys return nullptr; } - shared_lock readLock(abilityMapLock_); + shared_lock readLock(abilityMapLock_); auto iter = abilityMap_.find(systemAbilityId); if (iter == abilityMap_.end()) { HILOGI("GetSystemAbilityFromRemote not found SA %{public}d.", systemAbilityId); @@ -532,7 +532,7 @@ sptr SystemAbilityManager::CheckSystemAbility(int32_t systemAbili return nullptr; } int32_t count = UpdateSaFreMap(IPCSkeleton::GetCallingUid(), systemAbilityId); - shared_lock readLock(abilityMapLock_); + shared_lock readLock(abilityMapLock_); auto iter = abilityMap_.find(systemAbilityId); if (iter != abilityMap_.end()) { HILOGD("found SA:%{public}d,callpid:%{public}d", systemAbilityId, IPCSkeleton::GetCallingPid()); @@ -584,7 +584,7 @@ int32_t SystemAbilityManager::FindSystemAbilityNotify(int32_t systemAbilityId, c int32_t code) { HILOGI("FindSaNotify SA:%{public}d,%{public}d_%{public}zu", systemAbilityId, code, listenerMap_.size()); - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); auto iter = listenerMap_.find(systemAbilityId); if (iter == listenerMap_.end()) { return ERR_OK; @@ -664,7 +664,7 @@ int32_t SystemAbilityManager::AddOnDemandSystemAbilityInfo(int32_t systemAbility return ERR_INVALID_VALUE; } - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); auto onDemandSaSize = onDemandAbilityMap_.size(); if (onDemandSaSize >= MAX_SERVICES) { HILOGE("map size error, (Has been greater than %{public}zu)", @@ -672,7 +672,7 @@ int32_t SystemAbilityManager::AddOnDemandSystemAbilityInfo(int32_t systemAbility return ERR_INVALID_VALUE; } { - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); if (systemProcessMap_.count(procName) == 0) { HILOGW("AddOnDemandSystemAbilityInfo procName:%{public}s not exist.", Str16ToStr8(procName).c_str()); return ERR_INVALID_VALUE; @@ -696,7 +696,7 @@ int32_t SystemAbilityManager::AddOnDemandSystemAbilityInfo(int32_t systemAbility void SystemAbilityManager::RemoveOnDemandSaInDiedProc(std::shared_ptr& processContext) { - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); for (auto& saId : processContext->saList) { onDemandAbilityMap_.erase(saId); } @@ -741,7 +741,7 @@ sptr SystemAbilityManager::CheckSystemAbility(int32_t systemAbili bool SystemAbilityManager::DoLoadOnDemandAbility(int32_t systemAbilityId, bool& isExist) { - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); sptr abilityProxy = CheckSystemAbility(systemAbilityId); if (abilityProxy != nullptr) { isExist = true; @@ -769,7 +769,7 @@ int32_t SystemAbilityManager::RemoveSystemAbility(int32_t systemAbilityId) return ERR_INVALID_VALUE; } { - unique_lock writeLock(abilityMapLock_); + unique_lock writeLock(abilityMapLock_); auto itSystemAbility = abilityMap_.find(systemAbilityId); if (itSystemAbility == abilityMap_.end()) { HILOGI("RemoveSystemAbility not found!"); @@ -805,7 +805,7 @@ int32_t SystemAbilityManager::RemoveSystemAbility(const sptr& abi int32_t saId = 0; { - unique_lock writeLock(abilityMapLock_); + unique_lock writeLock(abilityMapLock_); for (auto iter = abilityMap_.begin(); iter != abilityMap_.end(); ++iter) { if (iter->second.remoteObj == ability) { saId = iter->first; @@ -838,7 +838,7 @@ int32_t SystemAbilityManager::RemoveSystemAbility(const sptr& abi int32_t SystemAbilityManager::RemoveDiedSystemAbility(int32_t systemAbilityId) { { - unique_lock writeLock(abilityMapLock_); + unique_lock writeLock(abilityMapLock_); auto itSystemAbility = abilityMap_.find(systemAbilityId); if (itSystemAbility == abilityMap_.end()) { return ERR_OK; @@ -858,7 +858,7 @@ int32_t SystemAbilityManager::RemoveDiedSystemAbility(int32_t systemAbilityId) vector SystemAbilityManager::ListSystemAbilities(uint32_t dumpFlags) { vector list; - shared_lock readLock(abilityMapLock_); + shared_lock readLock(abilityMapLock_); for (auto iter = abilityMap_.begin(); iter != abilityMap_.end(); iter++) { list.emplace_back(Str8ToStr16(to_string(iter->first))); } @@ -889,7 +889,7 @@ void SystemAbilityManager::CheckListenerNotify(int32_t systemAbilityId, if (targetObject == nullptr) { return; } - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); auto& listeners = listenerMap_[systemAbilityId]; for (auto& itemListener : listeners) { if (listener->AsObject() == itemListener.listener->AsObject()) { @@ -918,7 +918,7 @@ int32_t SystemAbilityManager::SubscribeSystemAbility(int32_t systemAbilityId, auto callingPid = IPCSkeleton::GetCallingPid(); { - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); auto& listeners = listenerMap_[systemAbilityId]; for (const auto& itemListener : listeners) { if (listener->AsObject() == itemListener.listener->AsObject()) { @@ -980,7 +980,7 @@ int32_t SystemAbilityManager::UnSubscribeSystemAbility(int32_t systemAbilityId, return ERR_INVALID_VALUE; } - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); auto& listeners = listenerMap_[systemAbilityId]; UnSubscribeSystemAbilityLocked(listeners, listener->AsObject()); if (abilityStatusDeath_ != nullptr) { @@ -992,7 +992,7 @@ int32_t SystemAbilityManager::UnSubscribeSystemAbility(int32_t systemAbilityId, void SystemAbilityManager::UnSubscribeSystemAbility(const sptr& remoteObject) { - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); HILOGD("UnSubscribeSA remote object dead! size:%{public}zu", listenerMap_.size()); for (auto& item : listenerMap_) { auto& listeners = item.second; @@ -1009,7 +1009,7 @@ void SystemAbilityManager::NotifyRemoteSaDied(const std::u16string& name) std::string deviceId; SamgrUtil::ParseRemoteSaName(name, deviceId, saName); #ifdef SAMGR_ENABLE_DELAY_DBINDER - std::shared_lock readLock(dBinderServiceLock_); + std::shared_lock readLock(dBinderServiceLock_); #endif if (dBinderService_ != nullptr) { std::string nodeId = SamgrUtil::TransformDeviceId(deviceId, NODE_ID, false); @@ -1022,7 +1022,7 @@ void SystemAbilityManager::NotifyRemoteSaDied(const std::u16string& name) void SystemAbilityManager::NotifyRemoteDeviceOffline(const std::string& deviceId) { #ifdef SAMGR_ENABLE_DELAY_DBINDER - std::shared_lock readLock(dBinderServiceLock_); + std::shared_lock readLock(dBinderServiceLock_); #endif if (dBinderService_ != nullptr) { dBinderService_->NoticeDeviceDie(deviceId); @@ -1032,7 +1032,7 @@ void SystemAbilityManager::NotifyRemoteDeviceOffline(const std::string& deviceId void SystemAbilityManager::RefreshListenerState(int32_t systemAbilityId) { - lock_guard autoLock(listenerMapLock_); + lock_guard autoLock(listenerMapLock_); auto iter = listenerMap_.find(systemAbilityId); if (iter != listenerMap_.end()) { auto& listeners = iter->second; @@ -1051,7 +1051,7 @@ int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sp } RefreshListenerState(systemAbilityId); { - unique_lock writeLock(abilityMapLock_); + unique_lock writeLock(abilityMapLock_); auto saSize = abilityMap_.size(); if (saSize >= MAX_SERVICES) { HILOGE("map size error, (Has been greater than %zu)", saSize); @@ -1107,7 +1107,7 @@ int32_t SystemAbilityManager::AddSystemProcess(const u16string& procName, return ERR_INVALID_VALUE; } { - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); size_t procNum = systemProcessMap_.size(); if (procNum >= MAX_SERVICES) { HILOGE("AddSystemProcess map size reach MAX_SERVICES already"); @@ -1121,7 +1121,7 @@ int32_t SystemAbilityManager::AddSystemProcess(const u16string& procName, } int64_t duration = 0; { - lock_guard autoLock(startingProcessMapLock_); + lock_guard autoLock(startingProcessMapLock_); auto iterStarting = startingProcessMap_.find(procName); if (iterStarting != startingProcessMap_.end()) { duration = GetTickCount() - iterStarting->second; @@ -1155,7 +1155,7 @@ int32_t SystemAbilityManager::RemoveSystemProcess(const sptr& pro procObject->RemoveDeathRecipient(systemProcessDeath_); } { - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); for (const auto& [procName, object] : systemProcessMap_) { if (object != procObject) { continue; @@ -1189,7 +1189,7 @@ sptr SystemAbilityManager::GetSystemProcess(const u16string& proc return nullptr; } - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); auto iter = systemProcessMap_.find(procName); if (iter != systemProcessMap_.end()) { HILOGD("process:%{public}s found", Str16ToStr8(procName).c_str()); @@ -1332,14 +1332,14 @@ void SystemAbilityManager::CleanCallbackForLoadFailed(int32_t systemAbilityId, c const std::string& srcDeviceId, const sptr& callback) { { - lock_guard autoLock(startingProcessMapLock_); + lock_guard autoLock(startingProcessMapLock_); auto iterStarting = startingProcessMap_.find(name); if (iterStarting != startingProcessMap_.end()) { HILOGI("CleanCallback clean process:%{public}s", Str16ToStr8(name).c_str()); startingProcessMap_.erase(iterStarting); } } - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); auto iter = startingAbilityMap_.find(systemAbilityId); if (iter == startingAbilityMap_.end()) { HILOGI("CleanCallback SA:%{public}d not in startingAbilityMap.", systemAbilityId); @@ -1415,7 +1415,7 @@ void SystemAbilityManager::NotifySystemAbilityLoaded(int32_t systemAbilityId, co void SystemAbilityManager::NotifySystemAbilityLoaded(int32_t systemAbilityId, const sptr& remoteObject) { - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); auto iter = startingAbilityMap_.find(systemAbilityId); if (iter == startingAbilityMap_.end()) { return; @@ -1491,7 +1491,7 @@ int32_t SystemAbilityManager::StartingSystemProcessLocked(const std::u16string& { bool isProcessStarted = false; { - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); isProcessStarted = (systemProcessMap_.count(procName) != 0); } if (isProcessStarted) { @@ -1501,7 +1501,7 @@ int32_t SystemAbilityManager::StartingSystemProcessLocked(const std::u16string& } // call init start process { - lock_guard autoLock(startingProcessMapLock_); + lock_guard autoLock(startingProcessMapLock_); if (startingProcessMap_.count(procName) != 0) { HILOGI("StartingProc:%{public}s already starting", Str16ToStr8(procName).c_str()); return ERR_OK; @@ -1512,7 +1512,7 @@ int32_t SystemAbilityManager::StartingSystemProcessLocked(const std::u16string& } int32_t result = StartDynamicSystemProcess(procName, systemAbilityId, event); if (result != ERR_OK) { - lock_guard autoLock(startingProcessMapLock_); + lock_guard autoLock(startingProcessMapLock_); auto iterStarting = startingProcessMap_.find(procName); if (iterStarting != startingProcessMap_.end()) { startingProcessMap_.erase(iterStarting); @@ -1526,7 +1526,7 @@ int32_t SystemAbilityManager::StartingSystemProcess(const std::u16string& procNa { bool isProcessStarted = false; { - lock_guard autoLock(systemProcessMapLock_); + lock_guard autoLock(systemProcessMapLock_); isProcessStarted = (systemProcessMap_.count(procName) != 0); } if (isProcessStarted) { @@ -1536,7 +1536,7 @@ int32_t SystemAbilityManager::StartingSystemProcess(const std::u16string& procNa } // call init start process { - lock_guard autoLock(startingProcessMapLock_); + lock_guard autoLock(startingProcessMapLock_); if (startingProcessMap_.count(procName) != 0) { HILOGI("StartingProc:%{public}s already starting", Str16ToStr8(procName).c_str()); return ERR_OK; @@ -1547,7 +1547,7 @@ int32_t SystemAbilityManager::StartingSystemProcess(const std::u16string& procNa } int32_t result = StartDynamicSystemProcess(procName, systemAbilityId, event); if (result != ERR_OK) { - lock_guard autoLock(startingProcessMapLock_); + lock_guard autoLock(startingProcessMapLock_); auto iterStarting = startingProcessMap_.find(procName); if (iterStarting != startingProcessMap_.end()) { startingProcessMap_.erase(iterStarting); @@ -1570,7 +1570,7 @@ int32_t SystemAbilityManager::DoLoadSystemAbility(int32_t systemAbilityId, const } int32_t result = ERR_INVALID_VALUE; { - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); auto& abilityItem = startingAbilityMap_[systemAbilityId]; for (const auto& itemCallback : abilityItem.callbackMap[LOCAL_DEVICE]) { if (callback->AsObject() == itemCallback.first->AsObject()) { @@ -1608,7 +1608,7 @@ int32_t SystemAbilityManager::DoLoadSystemAbilityFromRpc(const std::string& srcD return ERR_OK; } { - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); auto& abilityItem = startingAbilityMap_[systemAbilityId]; abilityItem.callbackMap[srcDeviceId].emplace_back(callback, 0); StartingSystemProcessLocked(procName, systemAbilityId, event); @@ -1710,7 +1710,7 @@ int32_t SystemAbilityManager::DoUnloadSystemAbility(int32_t systemAbilityId, return ERR_OK; } { - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); bool result = StopOnDemandAbilityInner(procName, systemAbilityId, event); if (!result) { HILOGE("unload system ability failed, SA:%{public}d", systemAbilityId); @@ -1824,7 +1824,7 @@ int32_t SystemAbilityManager::LoadSystemAbility(int32_t systemAbilityId, const s { std::string key = ToString(systemAbilityId) + "_" + deviceId; { - lock_guard autoLock(loadRemoteLock_); + lock_guard autoLock(loadRemoteLock_); auto& callbacks = remoteCallbacks_[key]; auto iter = std::find_if(callbacks.begin(), callbacks.end(), [callback](auto itemCallback) { return callback->AsObject() == itemCallback->AsObject(); @@ -1864,7 +1864,7 @@ void SystemAbilityManager::DoLoadRemoteSystemAbility(int32_t systemAbilityId, in callback->OnLoadSACompleteForRemote(deviceId, systemAbilityId, remoteBinder); std::string key = ToString(systemAbilityId) + "_" + deviceId; { - lock_guard autoLock(loadRemoteLock_); + lock_guard autoLock(loadRemoteLock_); if (remoteCallbackDeath_ != nullptr) { callback->AsObject()->RemoveDeathRecipient(remoteCallbackDeath_); } @@ -1901,7 +1901,7 @@ sptr SystemAbilityManager::DoMakeRemoteBinder(int32_t system #endif sptr remoteBinder = nullptr; #ifdef SAMGR_ENABLE_DELAY_DBINDER - std::shared_lock readLock(dBinderServiceLock_); + std::shared_lock readLock(dBinderServiceLock_); #endif if (dBinderService_ != nullptr) { string strName = to_string(systemAbilityId); @@ -1925,7 +1925,7 @@ void SystemAbilityManager::NotifyRpcLoadCompleted(const std::string& srcDeviceId } auto notifyTask = [srcDeviceId, systemAbilityId, remoteObject, this]() { #ifdef SAMGR_ENABLE_DELAY_DBINDER - std::shared_lock readLock(dBinderServiceLock_); + std::shared_lock readLock(dBinderServiceLock_); #endif if (dBinderService_ != nullptr) { SamgrXCollie samgrXCollie("samgr--LoadSystemAbilityComplete_" + ToString(systemAbilityId)); @@ -1991,7 +1991,7 @@ void SystemAbilityManager::OnAbilityCallbackDied(const sptr& remo if (remoteObject == nullptr) { return; } - lock_guard autoLock(onDemandLock_); + lock_guard autoLock(onDemandLock_); auto iter = startingAbilityMap_.begin(); while (iter != startingAbilityMap_.end()) { AbilityItem& abilityItem = iter->second; @@ -2010,7 +2010,7 @@ void SystemAbilityManager::OnRemoteCallbackDied(const sptr& remot if (remoteObject == nullptr) { return; } - lock_guard autoLock(loadRemoteLock_); + lock_guard autoLock(loadRemoteLock_); auto iter = remoteCallbacks_.begin(); while (iter != remoteCallbacks_.end()) { auto& callbacks = iter->second; @@ -2045,7 +2045,7 @@ int32_t SystemAbilityManager::UpdateSaFreMap(int32_t uid, int32_t saId) } uint64_t key = SamgrUtil::GenerateFreKey(uid, saId); - lock_guard autoLock(saFrequencyLock_); + lock_guard autoLock(saFrequencyLock_); auto& count = saFrequencyMap_[key]; if (count < MAX_SA_FREQUENCY_COUNT) { count++; @@ -2056,7 +2056,7 @@ int32_t SystemAbilityManager::UpdateSaFreMap(int32_t uid, int32_t saId) void SystemAbilityManager::ReportGetSAPeriodically() { HILOGI("ReportGetSAPeriodically start!"); - lock_guard autoLock(saFrequencyLock_); + lock_guard autoLock(saFrequencyLock_); for (const auto& [key, count] : saFrequencyMap_) { uint32_t saId = static_cast(key); uint32_t uid = key >> SHFIT_BIT; @@ -2110,7 +2110,7 @@ int32_t SystemAbilityManager::SendStrategy(int32_t type, std::vector& s int32_t SystemAbilityManager::GetExtensionSaIds(const std::string& extension, std::vector& saIds) { - lock_guard autoLock(saProfileMapLock_); + lock_guard autoLock(saProfileMapLock_); for (const auto& [saId, value] : saProfileMap_) { if (std::find(value.extension.begin(), value.extension.end(), extension) != value.extension.end()) { @@ -2123,11 +2123,11 @@ int32_t SystemAbilityManager::GetExtensionSaIds(const std::string& extension, st int32_t SystemAbilityManager::GetExtensionRunningSaList(const std::string& extension, std::vector>& saList) { - lock_guard autoLock(saProfileMapLock_); + lock_guard autoLock(saProfileMapLock_); for (const auto& [saId, value] : saProfileMap_) { if (std::find(value.extension.begin(), value.extension.end(), extension) != value.extension.end()) { - shared_lock readLock(abilityMapLock_); + shared_lock readLock(abilityMapLock_); auto iter = abilityMap_.find(saId); if (iter != abilityMap_.end() && iter->second.remoteObj != nullptr) { saList.push_back(iter->second.remoteObj); @@ -2141,7 +2141,7 @@ int32_t SystemAbilityManager::GetExtensionRunningSaList(const std::string& exten int32_t SystemAbilityManager::GetRunningSaExtensionInfoList(const std::string& extension, std::vector& infoList) { - lock_guard autoLock(saProfileMapLock_); + lock_guard autoLock(saProfileMapLock_); for (const auto& [saId, value] : saProfileMap_) { if (std::find(value.extension.begin(), value.extension.end(), extension) != value.extension.end()) { @@ -2150,7 +2150,7 @@ int32_t SystemAbilityManager::GetRunningSaExtensionInfoList(const std::string& e HILOGD("get SaExtInfoList sa not load,ext:%{public}s SA:%{public}d", extension.c_str(), saId); continue; } - shared_lock readLock(abilityMapLock_); + shared_lock readLock(abilityMapLock_); auto iter = abilityMap_.find(saId); if (iter == abilityMap_.end() || iter->second.remoteObj == nullptr) { HILOGD("getRunningSaExtInfoList SA:%{public}d not load,ext:%{public}s", saId, extension.c_str()); diff --git a/services/samgr/native/source/system_ability_manager_dumper.cpp b/services/samgr/native/source/system_ability_manager_dumper.cpp index aee4cd3471ef3f05cb2a56261ac8341b3ee907d4..0f0866586b8a45f867ecfa6a1d48544b27e433e0 100644 --- a/services/samgr/native/source/system_ability_manager_dumper.cpp +++ b/services/samgr/native/source/system_ability_manager_dumper.cpp @@ -62,7 +62,7 @@ constexpr const char* IPC_DUMP_FAIL = " fail\n"; std::shared_ptr SystemAbilityManagerDumper::handler_ = nullptr; char* SystemAbilityManagerDumper::ffrtMetricBuffer = nullptr; bool SystemAbilityManagerDumper::collectEnable = false; -std::mutex SystemAbilityManagerDumper::ffrtMetricLock; +samgr::mutex SystemAbilityManagerDumper::ffrtMetricLock; void SystemAbilityManagerDumper::ShowListenerHelp(string& result) { @@ -449,7 +449,7 @@ void SystemAbilityManagerDumper::ClearFfrtStatisticsBufferLocked() void SystemAbilityManagerDumper::ClearFfrtStatistics() { HILOGW("ClearFfrtStatistics start"); - std::lock_guard autoLock(ffrtMetricLock); + std::lock_guard autoLock(ffrtMetricLock); if (collectEnable) { auto ret = ffrt_dump(ffrt_dump_cmd_t::DUMP_STOP_STAT, ffrtMetricBuffer, BUFFER_SIZE); if (ret != ERR_OK) { @@ -462,7 +462,7 @@ void SystemAbilityManagerDumper::ClearFfrtStatistics() bool SystemAbilityManagerDumper::CollectFfrtStatistics(int32_t cmd, std::string& result) { - std::lock_guard autoLock(ffrtMetricLock); + std::lock_guard autoLock(ffrtMetricLock); result.append("pid:" + ToString(getpid()) + " "); auto ret = false; switch (cmd) { diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index d45162202abd5e71c9c94bbce2cfefee19af323a..c7902af39ceb1473aad39abe32354221bb0a377c 100644 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -162,6 +162,7 @@ ohos_unittest("SystemAbilityMgrTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_unittest("SystemAbilityMgrCollectTest") { @@ -302,6 +303,7 @@ ohos_unittest("SystemAbilityMgrCollectTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_unittest("SystemAbilityMgrDeviceNetworkingTest") { @@ -411,6 +413,7 @@ ohos_unittest("SystemAbilityMgrDeviceNetworkingTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_unittest("SystemAbilityMgrStubTest") { @@ -520,6 +523,7 @@ ohos_unittest("SystemAbilityMgrStubTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_unittest("SystemAbilityMgrProxyTest") { @@ -716,6 +720,7 @@ ohos_unittest("SystemAbilityStateSchedulerTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_unittest("SystemAbilityMgrDumperTest") { @@ -795,6 +800,7 @@ ohos_unittest("SystemAbilityMgrDumperTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_unittest("MockSystemAbilityManagerTest") { @@ -851,6 +857,7 @@ ohos_unittest("MockSystemAbilityManagerTest") { ] defines += [ "SUPPORT_ACCESS_TOKEN" ] } + defines += ["SAMGR_USE_FFRT"] } ohos_executable("manual_ondemand") { @@ -1055,6 +1062,7 @@ ohos_executable("TestTool") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] part_name = "samgr" subsystem_name = "systemabilitymgr" } diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp index ad459fba724524b20eac360c9dca814affa0a469..7435edddc7fd1cd2ec858d4c3e3934b738f56dd9 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp @@ -73,7 +73,7 @@ void SystemAbilityMgrStubLoadTest::AddSystemAbilityContext(int32_t systemAbility sptr saMgr = SystemAbilityManager::GetInstance(); EXPECT_TRUE(saMgr != nullptr); EXPECT_TRUE(saMgr->abilityStateScheduler_ != nullptr); - std::unique_lock processWriteLock(saMgr->abilityStateScheduler_->processMapLock_); + std::unique_lock processWriteLock(saMgr->abilityStateScheduler_->processMapLock_); if (saMgr->abilityStateScheduler_->processContextMap_.count(processName) == 0) { auto processContext = std::make_shared(); processContext->processName = processName; @@ -91,7 +91,7 @@ void SystemAbilityMgrStubLoadTest::AddSystemAbilityContext(int32_t systemAbility auto abilityContext = std::make_shared(); abilityContext->systemAbilityId = systemAbilityId; abilityContext->ownProcessContext = saMgr->abilityStateScheduler_->processContextMap_[processName]; - std::unique_lock abiltyWriteLock(saMgr->abilityStateScheduler_->abiltyMapLock_); + std::unique_lock abiltyWriteLock(saMgr->abilityStateScheduler_->abiltyMapLock_); saMgr->abilityStateScheduler_->abilityContextMap_[systemAbilityId] = abilityContext; } diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp index 9dc2c0c075d47b409913ef0332bd0474bdfdb111..07c8189c34b0ac4aad65341578d4911ebac258ca 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp @@ -90,7 +90,7 @@ void SystemAbilityMgrStubTest::AddSystemAbilityContext(int32_t systemAbilityId, sptr saMgr = SystemAbilityManager::GetInstance(); EXPECT_TRUE(saMgr != nullptr); EXPECT_TRUE(saMgr->abilityStateScheduler_ != nullptr); - std::unique_lock processWriteLock(saMgr->abilityStateScheduler_->processMapLock_); + std::unique_lock processWriteLock(saMgr->abilityStateScheduler_->processMapLock_); if (saMgr->abilityStateScheduler_->processContextMap_.count(processName) == 0) { auto processContext = std::make_shared(); processContext->processName = processName; @@ -108,7 +108,7 @@ void SystemAbilityMgrStubTest::AddSystemAbilityContext(int32_t systemAbilityId, auto abilityContext = std::make_shared(); abilityContext->systemAbilityId = systemAbilityId; abilityContext->ownProcessContext = saMgr->abilityStateScheduler_->processContextMap_[processName]; - std::unique_lock abiltyWriteLock(saMgr->abilityStateScheduler_->abiltyMapLock_); + std::unique_lock abiltyWriteLock(saMgr->abilityStateScheduler_->abiltyMapLock_); saMgr->abilityStateScheduler_->abilityContextMap_[systemAbilityId] = abilityContext; } diff --git a/test/fuzztest/samgr_fuzzer/BUILD.gn b/test/fuzztest/samgr_fuzzer/BUILD.gn index b4da073d18990da375e243ce7ef8d7d35a8c1d5a..f72c43a5996e0ba330234540dce90cd39bf7d9c6 100644 --- a/test/fuzztest/samgr_fuzzer/BUILD.gn +++ b/test/fuzztest/samgr_fuzzer/BUILD.gn @@ -215,6 +215,7 @@ foreach(item, samgr_fuzztests) { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } } diff --git a/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn b/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn index fa652753ed126f69826efdfcfcbcb1d74a4edef3..58dd770f7d8cce8aeca7a0a5cdf15ba405804415 100644 --- a/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn +++ b/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn @@ -116,6 +116,7 @@ ohos_fuzztest("SamgrCoverageFuzzTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } group("fuzztest") { diff --git a/test/fuzztest/samgrdumper_fuzzer/BUILD.gn b/test/fuzztest/samgrdumper_fuzzer/BUILD.gn index 20546c07b6ae7d5d04bb9878aae32492f7d8394b..536b4818c05e7608912b41eda56fb602c38a15d5 100644 --- a/test/fuzztest/samgrdumper_fuzzer/BUILD.gn +++ b/test/fuzztest/samgrdumper_fuzzer/BUILD.gn @@ -117,6 +117,7 @@ ohos_fuzztest("SamgrDumperFuzzTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } group("fuzztest") { diff --git a/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn b/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn index e25ea5d123b5b6c0ea064af3056d2b7316cf2c32..9c9a24aa880c2d3f583c5d47da52319c26bf2102 100644 --- a/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn @@ -116,6 +116,7 @@ ohos_fuzztest("SystemAbilityManagerFuzzTest") { external_deps += [ "penglai_mode_service:penglai_client" ] defines += [ "SUPPORT_PENGLAI_MODE" ] } + defines += ["SAMGR_USE_FFRT"] } group("fuzztest") {