From 3b0032b81993504da73778a58b0185c679ffa3ae Mon Sep 17 00:00:00 2001 From: gong-guilin Date: Tue, 19 Aug 2025 20:54:52 +0800 Subject: [PATCH] =?UTF-8?q?ffrt=E5=90=8C=E5=90=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=88=A0=E9=99=A4=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gong-guilin --- services/samgr/native/include/ffrt_handler.h | 3 +- services/samgr/native/source/ffrt_handler.cpp | 29 ++++++++++++------- .../native/source/system_ability_manager.cpp | 6 ---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/services/samgr/native/include/ffrt_handler.h b/services/samgr/native/include/ffrt_handler.h index 67edf3c6..9def766e 100644 --- a/services/samgr/native/include/ffrt_handler.h +++ b/services/samgr/native/include/ffrt_handler.h @@ -18,6 +18,7 @@ #include #include +#include #include "ffrt.h" #include "samgr_ffrt_api.h" @@ -38,7 +39,7 @@ public: private: samgr::shared_mutex mutex_; - std::map taskMap_; + std::map> taskMap_; std::shared_ptr queue_; }; } // namespace OHOS diff --git a/services/samgr/native/source/ffrt_handler.cpp b/services/samgr/native/source/ffrt_handler.cpp index 722bd947..936c7b3f 100644 --- a/services/samgr/native/source/ffrt_handler.cpp +++ b/services/samgr/native/source/ffrt_handler.cpp @@ -36,13 +36,18 @@ 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) { - auto ret = queue_->cancel(iter->second); - if (ret != 0) { - HILOGE("cancel task failed, error code %{public}d", ret); + if (queue_ != nullptr) { + for (auto& handler : iter->second) { + if (handler == nullptr) { + continue; + } + auto ret = queue_->cancel(handler); + if (ret != 0) { + HILOGE("cancel task failed, error code %{public}d", ret); + } + handler = nullptr; } } - iter->second = nullptr; } taskMap_.clear(); if (queue_ != nullptr) { @@ -104,7 +109,8 @@ bool FFRTHandler::PostTask(std::function func, const std::string& name, HILOGE("FFRTHandler post task failed"); return false; } - taskMap_[name] = std::move(handler); + auto& handlerList = taskMap_[name]; + handlerList.push_back(std::move(handler)); return true; } @@ -116,10 +122,13 @@ void FFRTHandler::RemoveTask(const std::string& name) HILOGW("rm task %{public}s NF", name.c_str()); return; } - if (item->second != nullptr) { - auto ret = queue_->cancel(item->second); - if (ret != 0) { - HILOGE("cancel task failed, error code %{public}d", ret); + for (auto& handler : item->second) { + if (handler != nullptr) { + auto ret = queue_->cancel(handler); + if (ret != 0) { + HILOGE("cancel task failed, error code %{public}d", ret); + } + handler = nullptr; } } taskMap_.erase(name); diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index 97b6c736..cbe98a9b 100644 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -1296,12 +1296,6 @@ void SystemAbilityManager::SendCheckLoadedMsg(int32_t systemAbilityId, const std } auto delayTask = [systemAbilityId, name, srcDeviceId, callback, this]() { - if (workHandler_ != nullptr) { - HILOGD("SendCheckLoadedMsg deltask SA:%{public}d", systemAbilityId); - workHandler_->DelTask(ToString(systemAbilityId)); - } else { - HILOGE("SendCheckLoadedMsg workHandler_ is null"); - } if (CheckSystemAbility(systemAbilityId) != nullptr) { HILOGI("SendCheckLoadedMsg SA:%{public}d loaded", systemAbilityId); return; -- Gitee