From 7e933a167f614f9bd7cba539a173b689721e28c3 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Thu, 20 Feb 2025 11:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=B9=E5=AE=9A=E6=97=B6=E5=BA=8F=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E8=AE=BE=E5=A4=87=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E4=B8=8B=E7=BA=BF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../include/task/task_board.h | 3 ++- .../src/task/offline_task.cpp | 6 +++--- .../src/task/task_board.cpp | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/task/task_board.h b/services/distributedhardwarefwkservice/include/task/task_board.h index a0e54c5e..92cc58bf 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 ea99ea93..5b9c0c90 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 08c028a9..e123d069 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_); -- Gitee