diff --git a/services/distributedhardwarefwkservice/include/task/task_board.h b/services/distributedhardwarefwkservice/include/task/task_board.h index a0e54c5e39b79729a3f3c1f03934759b9780ec82..92cc58bf652d5e644e3801d71267080985d643bd 100644 --- a/services/distributedhardwarefwkservice/include/task/task_board.h +++ b/services/distributedhardwarefwkservice/include/task/task_board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -31,6 +31,7 @@ class TaskBoard { DECLARE_SINGLE_INSTANCE(TaskBoard); public: bool IsAllTaskFinish(); + bool IsAllDisableTaskFinish(); void AddTask(std::shared_ptr task); void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); diff --git a/services/distributedhardwarefwkservice/src/task/offline_task.cpp b/services/distributedhardwarefwkservice/src/task/offline_task.cpp index ea99ea93b28521953639e6ed273dfad21747849a..5b9c0c9058ad9cbe0ab126b211cc34d64460630f 100644 --- a/services/distributedhardwarefwkservice/src/task/offline_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/offline_task.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -98,8 +98,8 @@ void OffLineTask::DoTaskInner() TaskBoard::GetInstance().RemoveTask(this->GetId()); if (DHContext::GetInstance().GetRealTimeOnlineDeviceCount() == 0 && DHContext::GetInstance().GetIsomerismConnectCount() == 0 && - TaskBoard::GetInstance().IsAllTaskFinish()) { - DHLOGI("all devices are offline, start to free the resource"); + TaskBoard::GetInstance().IsAllDisableTaskFinish()) { + DHLOGI("all devices are offline and all disable tasks are finished, start to free the resource"); DistributedHardwareManagerFactory::GetInstance().UnInit(); } } diff --git a/services/distributedhardwarefwkservice/src/task/task_board.cpp b/services/distributedhardwarefwkservice/src/task/task_board.cpp index 08c028a9fb07ecbd675f3e08944d27f95aad4268..e123d06981bead9ff6ef25e5d75dcbc07f0793d3 100644 --- a/services/distributedhardwarefwkservice/src/task/task_board.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_board.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -67,6 +67,22 @@ void TaskBoard::AddTask(std::shared_ptr task) this->tasks_.emplace(task->GetId(), task); } +bool TaskBoard::IsAllDisableTaskFinish() +{ + std::lock_guard lock(tasksMtx_); + int32_t disableCount = 0; + for (auto iter = tasks_.begin(); iter != tasks_.end(); iter++) { + if (iter->second->GetTaskType() == TaskType::DISABLE || iter->second->GetTaskType() == TaskType::META_DISABLE) { + disableCount++; + } + } + DHLOGI("DisableTask count: %{public}d", disableCount); + if (disableCount == 0) { + return true; + } + return false; +} + void TaskBoard::RemoveTask(std::string taskId) { std::lock_guard lock(tasksMtx_);