From 0811ca1e1736d646867f55ad7000409cb2917281 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Thu, 6 Feb 2025 11:23:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=89=B9=E5=AE=9A=E6=97=B6=E5=BA=8F?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E8=AE=BE=E5=A4=87=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=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 | 8 ++++- .../include/task/task_factory.h | 3 +- .../src/task/disable_task.cpp | 3 +- .../src/task/meta_disable_task.cpp | 3 +- .../src/task/offline_task.cpp | 4 +-- .../src/task/task_board.cpp | 35 ++++++++++++++++++- .../src/task/task_factory.cpp | 12 +++++-- 7 files changed, 58 insertions(+), 10 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/task/task_board.h b/services/distributedhardwarefwkservice/include/task/task_board.h index a0e54c5e..d979994a 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 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,9 @@ public: void DumpAllTasks(std::vector &taskInfos); bool IsEnabledDevice(const std::string &enabledDeviceKey); + void AddDisableTask(std::shared_ptr task); + void RemoveDisableTask(const std::string &taskId); + bool IsAllDisableTaskFinish(); private: void RemoveTaskInner(std::string taskId); @@ -52,6 +56,8 @@ private: /* The key is combination of deviceId and dhId, and the value is taskParam */ std::unordered_map enabledDevices_; std::mutex enabledDevicesMutex_; + std::unordered_map> disableTasks_; + std::shared_mutex disableTasksMtx_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/include/task/task_factory.h b/services/distributedhardwarefwkservice/include/task/task_factory.h index c52c5b3f..560e19f4 100644 --- a/services/distributedhardwarefwkservice/include/task/task_factory.h +++ b/services/distributedhardwarefwkservice/include/task/task_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -27,6 +27,7 @@ class TaskFactory { DECLARE_SINGLE_INSTANCE(TaskFactory); public: std::shared_ptr CreateTask(TaskType taskType, TaskParam taskParam, std::shared_ptr fatherTask); + void AddTask(TaskType taskType, std::shared_ptr fatherTask, std::shared_ptr task); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/disable_task.cpp b/services/distributedhardwarefwkservice/src/task/disable_task.cpp index 0314c571..16a4130b 100644 --- a/services/distributedhardwarefwkservice/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/disable_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 @@ -77,6 +77,7 @@ void DisableTask::DoTaskInner() std::string taskId = GetId(); std::shared_ptr father = GetFatherTask().lock(); TaskBoard::GetInstance().RemoveTask(taskId); + TaskBoard::GetInstance().RemoveDisableTask(taskId); /* if finish task, notify father finish */ if (father != nullptr) { auto offLineTask = std::static_pointer_cast(father); diff --git a/services/distributedhardwarefwkservice/src/task/meta_disable_task.cpp b/services/distributedhardwarefwkservice/src/task/meta_disable_task.cpp index 4326e476..e2327d48 100644 --- a/services/distributedhardwarefwkservice/src/task/meta_disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/meta_disable_task.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -69,6 +69,7 @@ void MetaDisableTask::DoTaskInner() std::string taskId = GetId(); std::shared_ptr father = GetFatherTask().lock(); TaskBoard::GetInstance().RemoveTask(taskId); + TaskBoard::GetInstance().RemoveDisableTask(taskId); /* if finish task, notify father finish */ if (father != nullptr) { auto offLineTask = std::static_pointer_cast(father); diff --git a/services/distributedhardwarefwkservice/src/task/offline_task.cpp b/services/distributedhardwarefwkservice/src/task/offline_task.cpp index ea99ea93..aedc343d 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,7 +98,7 @@ void OffLineTask::DoTaskInner() TaskBoard::GetInstance().RemoveTask(this->GetId()); if (DHContext::GetInstance().GetRealTimeOnlineDeviceCount() == 0 && DHContext::GetInstance().GetIsomerismConnectCount() == 0 && - TaskBoard::GetInstance().IsAllTaskFinish()) { + TaskBoard::GetInstance().IsAllDisableTaskFinish()) { DHLOGI("all devices are offline, 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..8c49da92 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 @@ -87,6 +87,39 @@ void TaskBoard::RemoveTaskInner(std::string taskId) tasks_.erase(taskId); } +void TaskBoard::AddDisableTask(std::shared_ptr task) +{ + if (task == nullptr) { + DHLOGE("task is null, error"); + return; + } + + std::unique_lock lock(disableTasksMtx_); + DHLOGI("Add disabletask, id: %{public}s", task->GetId().c_str()); + if (this->disableTasks_.find(task->GetId()) != this->disableTasks_.end()) { + DHLOGE("Task id duplicate, id: %{public}s", task->GetId().c_str()); + return; + } + this->disableTasks_.emplace(task->GetId(), task); +} + +void TaskBoard::RemoveDisableTask(const std::string &taskId) +{ + std::unique_lock lock(disableTasksMtx_); + DHLOGI("Remove disabletask, id: %{public}s", taskId.c_str()); + if (disableTasks_.find(taskId) == disableTasks_.end()) { + DHLOGE("Can not find removed task"); + return; + } + disableTasks_.erase(taskId); +} + +bool TaskBoard::IsAllDisableTaskFinish() +{ + std::shared_lock lock(disableTasksMtx_); + return this->disableTasks_.empty(); +} + void TaskBoard::DumpAllTasks(std::vector &taskInfos) { std::lock_guard lock(tasksMtx_); diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index 36ebbfe2..daa2022d 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.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 @@ -73,14 +73,20 @@ std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskP return nullptr; } } + AddTask(taskType, fatherTask, task); + return task; +} +void TaskFactory::AddTask(TaskType taskType, std::shared_ptr fatherTask, std::shared_ptr task) +{ if (fatherTask != nullptr) { task->SetFatherTask(fatherTask); fatherTask->AddChildrenTask(task); } TaskBoard::GetInstance().AddTask(task); - - return task; + if (taskType == TaskType::DISABLE || taskType == TaskType::META_DISABLE) { + TaskBoard::GetInstance().AddDisableTask(task); + } } } // namespace DistributedHardware } // namespace OHOS -- Gitee From c5dbead67280b4d8c765ad664c70ff0144b9f142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A4=A9=E5=88=9A?= Date: Fri, 14 Feb 2025 09:06:46 +0000 Subject: [PATCH 2/2] update services/distributedhardwarefwkservice/include/task/task_factory.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李天刚 --- .../distributedhardwarefwkservice/include/task/task_factory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/task/task_factory.h b/services/distributedhardwarefwkservice/include/task/task_factory.h index 6d4e17f2..037c9287 100644 --- a/services/distributedhardwarefwkservice/include/task/task_factory.h +++ b/services/distributedhardwarefwkservice/include/task/task_factory.h @@ -26,11 +26,11 @@ namespace DistributedHardware { class TaskFactory { DECLARE_SINGLE_INSTANCE(TaskFactory); public: - std::shared_ptr CreateTask(TaskType taskType, TaskParam taskParam, std::shared_ptr fatherTask); + std::shared_ptr CreateTask(TaskType taskType, TaskParam taskParam, std::shared_ptr fatherTask); private: - void AddTask(TaskType taskType, std::shared_ptr fatherTask, std::shared_ptr task); std::shared_ptr CreateEnableTask(const TaskParam &taskParam); std::shared_ptr CreateDisableTask(const TaskParam &taskParam); + void AddTask(TaskType taskType, std::shared_ptr fatherTask, std::shared_ptr task); }; } // namespace DistributedHardware } // namespace OHOS -- Gitee