!11693 使用ffrt提供的任务id

Merge pull request !11693 from wangzhen/ffrt_task
This commit is contained in:
openharmony_ci 2024-11-22 10:45:50 +00:00 committed by Gitee
commit f7a7d06d19
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 38 additions and 34 deletions

View File

@ -427,7 +427,7 @@ void AbilityManagerService::InitPushTask()
auto task = []() {
ApplicationUtil::AppFwkBootEventCallback(BOOTEVENT_BOOT_COMPLETED, "true", nullptr);
};
handler->SubmitTask(task, "BootCompletedDelayTask", BOOTEVENT_COMPLETED_DELAY_TIME);
handler->SubmitTaskJust(task, "BootCompletedDelayTask", BOOTEVENT_COMPLETED_DELAY_TIME);
} else {
WatchParameter(BOOTEVENT_BOOT_COMPLETED, ApplicationUtil::AppFwkBootEventCallback, nullptr);
TAG_LOGI(AAFwkTag::ABILITYMGR, "init call, InitPushTask suc");
@ -9350,7 +9350,7 @@ void AbilityManagerService::InitFocusListener()
}
};
if (taskHandler_) {
taskHandler_->SubmitTask(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY);
taskHandler_->SubmitTaskJust(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY);
}
}

View File

@ -531,7 +531,7 @@ void ConnectionStateManager::InitAppStateObserver()
}
self->InitAppStateObserver();
};
handler_->SubmitTask(initConnectionStateManagerTask, "InitConnectionStateManager", DELAY_TIME);
handler_->SubmitTaskJust(initConnectionStateManagerTask, "InitConnectionStateManager", DELAY_TIME);
retry_++;
}
return;

View File

@ -1459,7 +1459,7 @@ void UIAbilityLifecycleManager::DelayCompleteTerminate(const std::shared_ptr<Abi
self->CompleteTerminate(abilityRecord);
};
int killTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * KILL_TIMEOUT_MULTIPLE;
handler->SubmitTask(timeoutTask, "DELAY_KILL_PROCESS", killTimeout);
handler->SubmitTaskJust(timeoutTask, "DELAY_KILL_PROCESS", killTimeout);
}
void UIAbilityLifecycleManager::CompleteTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord)

View File

@ -972,7 +972,7 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr<AppRunning
}
// As taskHandler_ is busy now, the task should be submit to other task queue.
if (otherTaskHandler_ != nullptr) {
otherTaskHandler_->SubmitTask([appRecord, abilityInfo, pThis = shared_from_this()]() {
otherTaskHandler_->SubmitTaskJust([appRecord, abilityInfo, pThis = shared_from_this()]() {
pThis->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_SET_COLD_START, false, false);
pThis->SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::COLD);
}, "AppStateChangedNotify", FIRST_FRAME_NOTIFY_TASK_DELAY);
@ -1665,7 +1665,7 @@ void AppMgrServiceInner::SendProcessExitEventTask(
auto sendEventTask = [inner = shared_from_this(), appRecord, exitTime, count] () {
inner->SendProcessExitEventTask(appRecord, exitTime, count);
};
taskHandler_->SubmitTask(sendEventTask, PROCESS_EXIT_EVENT_TASK, KILL_PROCESS_DELAYTIME_MICRO_SECONDS);
taskHandler_->SubmitTaskJust(sendEventTask, PROCESS_EXIT_EVENT_TASK, KILL_PROCESS_DELAYTIME_MICRO_SECONDS);
}
void AppMgrServiceInner::SendProcessExitEvent(const std::shared_ptr<AppRunningRecord> &appRecord)
@ -4022,7 +4022,7 @@ void AppMgrServiceInner::TerminateApplication(const std::shared_ptr<AppRunningRe
TAG_LOGE(AAFwkTag::APPMGR, "taskHandler_ null");
return;
}
taskHandler_->SubmitTask(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT);
taskHandler_->SubmitTaskJust(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT);
}
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
if (!GetAppRunningStateByBundleName(appRecord->GetBundleName())) {
@ -5003,7 +5003,7 @@ void AppMgrServiceInner::KillApplicationByRecord(const std::shared_ptr<AppRunnin
return;
}
};
taskHandler_->SubmitTask(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT);
taskHandler_->SubmitTaskJust(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT);
}
void AppMgrServiceInner::SendHiSysEvent(int32_t innerEventId, std::shared_ptr<AppRunningRecord> appRecord)
@ -5603,7 +5603,7 @@ void AppMgrServiceInner::InitFocusListener()
}
};
if (taskHandler_) {
taskHandler_->SubmitTask(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY);
taskHandler_->SubmitTaskJust(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY);
TAG_LOGI(AAFwkTag::APPMGR, "submit registerFocusListenerTask");
}
}
@ -5795,7 +5795,7 @@ void AppMgrServiceInner::InitWindowPidVisibilityChangedListener()
TAG_LOGE(AAFwkTag::APPMGR, "Task handler is nullptr.");
return;
}
taskHandler_->SubmitTask(registerTask, "RegisterPidVisibilityListener.", REGISTER_PID_VISIBILITY_DELAY);
taskHandler_->SubmitTaskJust(registerTask, "RegisterPidVisibilityListener.", REGISTER_PID_VISIBILITY_DELAY);
}
void AppMgrServiceInner::FreeWindowPidVisibilityChangedListener()
@ -5992,7 +5992,7 @@ void AppMgrServiceInner::AppRecoveryNotifyApp(int32_t pid, const std::string& bu
}
};
constexpr int32_t timeOut = 2000;
taskHandler_->SubmitTask(waitSaveTask, timeOutName, timeOut);
taskHandler_->SubmitTaskJust(waitSaveTask, timeOutName, timeOut);
}
void AppMgrServiceInner::ParseInfoToAppfreeze(const FaultData &faultData, int32_t pid, int32_t uid,
@ -6079,7 +6079,7 @@ int32_t AppMgrServiceInner::SubmitDfxFaultTask(const FaultData &faultData, const
auto task = [pid, innerService = shared_from_this()]() {
AppExecFwk::AppfreezeManager::GetInstance()->DeleteStack(pid);
};
dfxTaskHandler_->SubmitTask(task, "DeleteStack", delayTime);
dfxTaskHandler_->SubmitTaskJust(task, "DeleteStack", delayTime);
return ERR_OK;
}
@ -6173,7 +6173,7 @@ int32_t AppMgrServiceInner::KillFaultApp(int32_t pid, const std::string &bundleN
};
constexpr int32_t waitTime = 3500;
// wait 3.5s before kill application
taskHandler_->SubmitTask(killAppTask, "killAppTask", waitTime);
taskHandler_->SubmitTaskJust(killAppTask, "killAppTask", waitTime);
return ERR_OK;
}
@ -6286,7 +6286,7 @@ bool AppMgrServiceInner::SetAppFreezeFilter(int32_t pid)
AppExecFwk::AppfreezeManager::GetInstance()->ResetAppfreezeState(pid, bundleName);
};
constexpr int32_t waitTime = 120000; // wait 2min
dfxTaskHandler_->SubmitTask(resetAppfreezeTask, "resetAppfreezeTask", waitTime);
dfxTaskHandler_->SubmitTaskJust(resetAppfreezeTask, "resetAppfreezeTask", waitTime);
return cancelResult;
}
TAG_LOGE(AAFwkTag::APPDFR, "SetAppFreezeFilter failed, pid %{public}d calling pid %{public}d",
@ -7077,7 +7077,7 @@ void AppMgrServiceInner::ClearResidentProcessAppRunningData(const std::shared_pt
}
restartResidentTaskList_.emplace_back(appRecord);
TAG_LOGD(AAFwkTag::APPMGR, "Post restart resident process delay task.");
taskHandler_->SubmitTask(restartProcess, "RestartResidentProcessDelayTask", RESTART_INTERVAL_TIME);
taskHandler_->SubmitTaskJust(restartProcess, "RestartResidentProcessDelayTask", RESTART_INTERVAL_TIME);
}
}
}
@ -8325,7 +8325,7 @@ bool AppMgrServiceInner::CleanAbilityByUserRequest(const sptr<IRemoteObject> &to
self->DecreaseWillKillPidsNum();
TAG_LOGD(AAFwkTag::APPMGR, "pid:%{public}d killed", targetPid);
};
delayKillTaskHandler_->SubmitTask(delayKillTask, "delayKillUIAbility", delayTime);
delayKillTaskHandler_->SubmitTaskJust(delayKillTask, "delayKillUIAbility", delayTime);
return true;
}

View File

@ -60,7 +60,7 @@ void KillingProcessManager::AddKillingCallerKey(const std::string& callerKey)
auto task = [callerKey] () {
KillingProcessManager::GetInstance().RemoveKillingCallerKey(callerKey);
};
taskHandler->SubmitTask(task, "clearCallerKey", CLEAR_CALLER_KEY_DELAY_TIME);
taskHandler->SubmitTaskJust(task, "clearCallerKey", CLEAR_CALLER_KEY_DELAY_TIME);
}
void KillingProcessManager::RemoveKillingCallerKey(const std::string& callerKey)

View File

@ -51,10 +51,7 @@ public:
{
return status_ && innerTaskHandle_;
}
int32_t GetTaskId() const
{
return taskId_;
}
uint64_t GetTaskId() const;
bool PrintTaskLog() const
{
return printTaskLog_;
@ -64,7 +61,6 @@ private:
std::shared_ptr<InnerTaskHandle> innerTaskHandle_;
std::shared_ptr<TaskStatus> status_;
int32_t taskId_ = 0;
bool printTaskLog_ = false;
};
@ -115,8 +111,6 @@ protected:
}
bool RemoveTask(const std::string &name, const TaskHandle &taskHandle);
protected:
static std::atomic_int32_t g_taskId;
// this is used only for compatibility
std::unordered_map<std::string, TaskHandle> tasks_;
std::unique_ptr<ffrt::mutex> tasksMutex_;

View File

@ -33,6 +33,11 @@ public:
{
return taskHandle_;
}
uint64_t GetId()
{
return taskHandle_.get_id();
}
private:
ffrt::task_handle taskHandle_;
};

View File

@ -58,7 +58,13 @@ void TaskHandle::Sync() const
handler->WaitTaskInner(innerTaskHandle_);
}
std::atomic_int32_t TaskHandlerWrap::g_taskId = 0;
uint64_t TaskHandle::GetTaskId() const
{
if (innerTaskHandle_) {
return innerTaskHandle_->GetId();
}
return 0;
}
std::shared_ptr<TaskHandlerWrap> TaskHandlerWrap::CreateQueueHandler(const std::string &queueName,
TaskQoS queueQos)
@ -144,23 +150,22 @@ TaskHandle TaskHandlerWrap::SubmitTask(const std::function<void()> &task, const
}
TaskHandle result(shared_from_this(), nullptr);
result.taskId_ = ++g_taskId;
result.printTaskLog_ = printTaskLog_;
auto taskWrap = [result, task, taskName = taskAttr.taskName_]() {
if (result.PrintTaskLog()) {
TAG_LOGW(AAFwkTag::DEFAULT, "begin execute task name: %{public}s, taskId: %{public}d",
taskName.c_str(), result.GetTaskId());
TAG_LOGW(AAFwkTag::DEFAULT, "begin execute task name: %{public}s, taskId: %{public}" PRIu64"",
taskName.c_str(), ffrt::this_task::get_id());
}
*result.status_ = TaskStatus::EXECUTING;
task();
*result.status_ = TaskStatus::FINISHED;
};
if (printTaskLog_) {
TAG_LOGW(AAFwkTag::DEFAULT, "submitTask: %{public}s, taskId: %{public}d, queueName: %{public}s count: "
"%{public}" PRIu64"", taskAttr.taskName_.c_str(), result.taskId_, queueName_.c_str(), GetTaskCount());
}
result.innerTaskHandle_ = SubmitTaskInner(std::move(taskWrap), taskAttr);
if (printTaskLog_) {
TAG_LOGW(AAFwkTag::DEFAULT, "submitTask: %{public}s, taskId: %{public}" PRIu64", queueName: %{public}s count: "
"%{public}" PRIu64"", taskAttr.taskName_.c_str(), result.GetTaskId(), queueName_.c_str(), GetTaskCount());
}
return result;
}
@ -176,8 +181,8 @@ bool TaskHandlerWrap::CancelTask(const std::string &name)
auto taskHandle = it->second;
tasks_.erase(it);
if (printTaskLog_) {
TAG_LOGW(AAFwkTag::DEFAULT, "cancel task name: %{public}s, taskId: %{public}d, queueName: %{public}s",
name.c_str(), taskHandle.taskId_, queueName_.c_str());
TAG_LOGW(AAFwkTag::DEFAULT, "cancel task name: %{public}s, taskId: %{public}" PRIu64", queueName: %{public}s",
name.c_str(), taskHandle.GetTaskId(), queueName_.c_str());
}
return taskHandle.Cancel();
}