diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index 91c8df2c3ed613166f1e4b3069d510517ae372ec..f821511191b39a9c328c60ddd7ab4e9ffa9b435b 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.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 @@ -50,6 +50,8 @@ private: private: std::atomic isInit_ = false; std::atomic flagUnInit_ = false; + std::atomic releaseStatus_ = false; + std::mutex releaseProcessMutex_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index e3ba58399317c9106d6a89646792b39f9cb6966b..1b6a741174e02665b994efc6956654fc79bf1df7 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -86,6 +86,7 @@ bool DistributedHardwareManagerFactory::Init() return false; } isInit_.store(true); + releaseStatus_.store(false); DHLOGI("success"); return true; } @@ -93,6 +94,12 @@ bool DistributedHardwareManagerFactory::Init() void DistributedHardwareManagerFactory::UnInit() { DHLOGI("start"); + std::lock_guard lock(releaseProcessMutex_); + if (releaseStatus_.load()) { + DHLOGE("Releasing resources is complete, not need to be released again."); + return; + } + releaseStatus_.store(true); DHTraceStart(COMPONENT_UNLOAD_START); HiSysEventWriteMsg(DHFWK_EXIT_BEGIN, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "dhfwk sa exit begin.");