refactor: kill in batch

Signed-off-by: yangxuguang-huawei <yangxuguang3@huawei.com>
This commit is contained in:
yangxuguang-huawei 2024-11-19 09:50:41 +08:00
parent 84bb8d4dc7
commit 208a8aa7ef
3 changed files with 3 additions and 22 deletions

View File

@ -104,8 +104,7 @@
"zlib" "zlib"
], ],
"third_party": [ "third_party": [
"libjpeg-turbo", "libjpeg-turbo"
"googletest"
] ]
}, },
"build": { "build": {

View File

@ -1931,8 +1931,6 @@ private:
std::atomic<int32_t> willKillPidsNum_ = 0; std::atomic<int32_t> willKillPidsNum_ = 0;
std::shared_ptr<AAFwk::TaskHandlerWrap> delayKillTaskHandler_; std::shared_ptr<AAFwk::TaskHandlerWrap> delayKillTaskHandler_;
std::unordered_set<std::string> nwebPreloadSet_ {}; std::unordered_set<std::string> nwebPreloadSet_ {};
ffrt::mutex killedBundleSetMutex_;
std::set<std::string> killedBundleSet_;
}; };
} // namespace AppExecFwk } // namespace AppExecFwk
} // namespace OHOS } // namespace OHOS

View File

@ -628,13 +628,6 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail"); TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail");
return; return;
} }
{
std::lock_guard lock(killedBundleSetMutex_);
if (killedBundleSet_.find(abilityInfo->bundleName) != killedBundleSet_.end()) {
TAG_LOGW(AAFwkTag::APPMGR, "%{public}s is being killed", abilityInfo->bundleName.c_str());
return;
}
}
if (abilityInfo->type == AbilityType::PAGE) { if (abilityInfo->type == AbilityType::PAGE) {
AbilityRuntime::FreezeUtil::LifecycleFlow flow = {loadParam->token, AbilityRuntime::FreezeUtil::LifecycleFlow flow = {loadParam->token,
AbilityRuntime::FreezeUtil::TimeoutState::LOAD}; AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
@ -2927,25 +2920,16 @@ int32_t AppMgrServiceInner::KillProcessesInBatch(const std::vector<int32_t> &pid
TAG_LOGE(AAFwkTag::APPMGR, "not supported."); TAG_LOGE(AAFwkTag::APPMGR, "not supported.");
return AAFwk::ERR_CAPABILITY_NOT_SUPPORT; return AAFwk::ERR_CAPABILITY_NOT_SUPPORT;
} }
std::vector<int32_t> killPids;
for (const auto& pid: pids) { for (const auto& pid: pids) {
auto appRecord = GetAppRunningRecordByPid(pid); auto appRecord = GetAppRunningRecordByPid(pid);
if (appRecord == nullptr) { if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord null"); TAG_LOGE(AAFwkTag::APPMGR, "appRecord null");
continue; continue;
} }
killPids.emplace_back(pid); std::string callerKey = std::to_string(pid) + ":" + std::to_string(appRecord->GetUid());
std::string bundleName = appRecord->GetBundleName(); KillingProcessManager::GetInstance().AddKillingCallerKey(callerKey);
{
std::lock_guard lock(killedBundleSetMutex_);
killedBundleSet_.insert(bundleName);
}
}
std::lock_guard lock(killedBundleSetMutex_);
for (const auto& pid: killPids) {
(void)KillProcessByPid(pid, "KillProcessesInBatch"); (void)KillProcessByPid(pid, "KillProcessesInBatch");
} }
killedBundleSet_.clear();
return ERR_OK; return ERR_OK;
} }