diff --git a/services/samgr/native/include/ffrt_handler.h b/services/samgr/native/include/ffrt_handler.h index 67edf3c678e8f130e3a9de74e223a12f29a8d831..9def766e693bc4d9ec87c49764ca639393cb05e8 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 722bd94711f7afc3369e3d3b63975893cb72d1ff..936c7b3f1def5f9e789f5db41fc9ca95484dfb3e 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 97b6c73620fb51fbf1a12a436345273b584c037f..cbe98a9b329e864b3b55b9ebaf2f45eceae68a15 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;