From f09621c554e1a9aa758a5cf5f69b444ee5a0e6de Mon Sep 17 00:00:00 2001 From: tangfan Date: Thu, 10 Nov 2022 11:48:35 +0800 Subject: [PATCH 1/2] add low latency in dhfwk Signed-off-by: tangfan --- common/utils/include/constants.h | 1 + common/utils/include/ipublisher_listener.h | 4 +- distributedhardwarefwk.gni | 4 + .../distributedhardwarefwkservice/BUILD.gn | 9 ++ .../componentmanager/component_manager.h | 4 +- .../include/lowlatency/low_latency.h | 43 +++++++++ .../include/lowlatency/low_latency_listener.h | 34 +++++++ .../componentmanager/component_manager.cpp | 14 ++- .../src/lowlatency/low_latency.cpp | 89 +++++++++++++++++++ .../src/lowlatency/low_latency_listener.cpp | 62 +++++++++++++ .../src/publisher/publisher.cpp | 3 +- .../fuzztest/componentmanager_fuzzer/BUILD.gn | 1 + .../unittest/common/componentmanager/BUILD.gn | 1 + utils/BUILD.gn | 1 + utils/include/dh_utils_tool.h | 6 ++ utils/src/dh_utils_tool.cpp | 12 +++ 16 files changed, 284 insertions(+), 4 deletions(-) create mode 100644 services/distributedhardwarefwkservice/include/lowlatency/low_latency.h create mode 100644 services/distributedhardwarefwkservice/include/lowlatency/low_latency_listener.h create mode 100644 services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp create mode 100644 services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp diff --git a/common/utils/include/constants.h b/common/utils/include/constants.h index 319daed2..aa888ece 100644 --- a/common/utils/include/constants.h +++ b/common/utils/include/constants.h @@ -58,6 +58,7 @@ namespace DistributedHardware { const std::string DH_COMPONENT_TYPE = "dhType"; const std::string DH_COMPONENT_SINK_VER = "version"; const std::string DH_COMPONENT_DEFAULT_VERSION = "1.0"; + const std::string LOW_LATENCY_ENABLE = "low_latency_enable"; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/common/utils/include/ipublisher_listener.h b/common/utils/include/ipublisher_listener.h index 5ac03510..5a4938ec 100644 --- a/common/utils/include/ipublisher_listener.h +++ b/common/utils/include/ipublisher_listener.h @@ -34,8 +34,10 @@ enum class DHTopic : uint32_t { TOPIC_STOP_DSCREEN = 3, // publish device offline message TOPIC_DEV_OFFLINE = 4, + // publish low latency message + TOPIC_LOW_LATENCY = 5, // Topic max border, not use for real topic - TOPIC_MAX = 5 + TOPIC_MAX = 6 }; class IPublisherListener : public IRemoteBroker { diff --git a/distributedhardwarefwk.gni b/distributedhardwarefwk.gni index 9bbb9538..54ae18f1 100644 --- a/distributedhardwarefwk.gni +++ b/distributedhardwarefwk.gni @@ -23,3 +23,7 @@ services_path = "${distributedhardwarefwk_path}/services" innerkits_path = "${distributedhardwarefwk_path}/interfaces/inner_kits" build_flags = [ "-Werror" ] + +declare_args() { + dhardware_low_latency = false +} diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index cafb1d86..b50d304b 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -43,6 +43,8 @@ ohos_shared_library("distributedhardwarefwksvr") { "include/hidumphelper", "include/ipc", "${utils_path}/include/eventbus", + "include/lowlatency", + "//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client/include", ] sources = [ @@ -80,12 +82,15 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/task/task_factory.cpp", "src/utils/dh_context.cpp", "src/versionmanager/version_manager.cpp", + "src/lowlatency/low_latency.cpp", + "src/lowlatency/low_latency_listener.cpp", ] deps = [ "${utils_path}:distributedhardwareutils", "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client:ressched_client", ] defines = [ @@ -94,6 +99,10 @@ ohos_shared_library("distributedhardwarefwksvr") { "LOG_DOMAIN=0xD004100", ] + if (dhardware_low_latency) { + defines += [ "DHARDWARE_LOW_LATENCY" ] + } + external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 6ec6d7e9..5d94b26e 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -28,6 +28,7 @@ #include "idistributed_hardware.h" #include "idistributed_hardware_sink.h" #include "idistributed_hardware_source.h" +#include "low_latency_listener.h" #include "version_info.h" namespace OHOS { @@ -87,7 +88,8 @@ private: std::map compSource_; std::map compSink_; std::map compSrcSaId_; - std::shared_ptr compMonitorPtr_; + std::shared_ptr compMonitorPtr_ = nullptr; + sptr lowLatencyListener_ = nullptr; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h b/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h new file mode 100644 index 00000000..7000be84 --- /dev/null +++ b/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_H + +#include + +#include "device_type.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class LowLatency { +DECLARE_SINGLE_INSTANCE_BASE(LowLatency); +public: + void EnableLowLatency(DHType dhType); + void DisableLowLatency(DHType dhType); + void CloseLowLatency(); + +private: + LowLatency() = default; + ~LowLatency() = default; + +private: + std::unordered_set lowLatencySwitchSet_; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_H diff --git a/services/distributedhardwarefwkservice/include/lowlatency/low_latency_listener.h b/services/distributedhardwarefwkservice/include/lowlatency/low_latency_listener.h new file mode 100644 index 00000000..fdbc0489 --- /dev/null +++ b/services/distributedhardwarefwkservice/include/lowlatency/low_latency_listener.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_H + +#include "ipublisher_listener.h" +#include "low_latency.h" + +namespace OHOS { +namespace DistributedHardware { +class LowLatencyListener : public IPublisherListener { +public: + LowLatencyListener()=default; + ~LowLatencyListener()=default; + void OnMessage(const DHTopic topic, const std::string& message) override; + sptr AsObject() override; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_H diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index c53739b6..40873405 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -37,7 +37,9 @@ #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "enabled_comps_dump.h" +#include "low_latency.h" #include "monitor_task_timer.h" +#include "publisher.h" #include "task_executor.h" #include "task_factory.h" #include "version_info_manager.h" @@ -58,7 +60,7 @@ namespace { } ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}), - compMonitorPtr_(std::make_shared()) + compMonitorPtr_(std::make_shared()), lowLatencyListener_(new(std::nothrow) LowLatencyListener) { DHLOGI("Ctor ComponentManager"); } @@ -66,6 +68,9 @@ ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSa ComponentManager::~ComponentManager() { DHLOGD("Dtor ComponentManager"); + compMonitorPtr_.reset(); + compMonitorPtr_ = nullptr; + lowLatencyListener_ = nullptr; } int32_t ComponentManager::Init() @@ -109,6 +114,9 @@ int32_t ComponentManager::Init() "dhfwk start sink failed."); } MonitorTaskTimer::GetInstance().StartTimer(); +#ifdef DHARDWARE_LOW_LATENCY + Publisher::GetInstance().RegisterListener(DHTopic::TOPIC_LOW_LATENCY, lowLatencyListener_); +#endif DHLOGI("Init component success"); DHTraceEnd(); return DH_FWK_SUCCESS; @@ -141,6 +149,10 @@ int32_t ComponentManager::UnInit() compSink_.clear(); MonitorTaskTimer::GetInstance().StopTimer(); +#ifdef DHARDWARE_LOW_LATENCY + Publisher::GetInstance().UnregisterListener(DHTopic::TOPIC_LOW_LATENCY, lowLatencyListener_); + LowLatency::GetInstance().CloseLowLatency(); +#endif DHLOGI("Release component success"); return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp new file mode 100644 index 00000000..5fe7c246 --- /dev/null +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "low_latency.h" + +#include + +#include "res_sched_client.h" +#include "res_type.h" + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(LowLatency); + +namespace { + constexpr int32_t MODE_ENABLE = 0; + constexpr int32_t MODE_DISABLE = 1; + constexpr uint32_t MAX_SWITCH_SIZE = 256; + const std::string KEY = "identity"; + const std::string PKG_NAME = "ohos.DistributedHardware"; +} + +void LowLatency::EnableLowLatency(DHType dhType) +{ + DHLOGI("Start EnableLowLatency dhType: %#X", dhType); + if (dhType <= DHType::UNKNOWN || dhType >= DHType::MAX_DH) { + DHLOGE("DHType is invalid, dhType: %" PRIu32, (uint32_t)dhType); + return; + } + DHLOGI("lowLatencySwitchSet size: %d", lowLatencySwitchSet_.size()); + if (lowLatencySwitchSet_.empty()) { + DHLOGD("Open LowLatency dhType: %#X", dhType); + auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance(); + // to enable low latency mode: value = 0 + rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_ENABLE, + {{KEY, PKG_NAME}}); + } + if (lowLatencySwitchSet_.size() >= MAX_SWITCH_SIZE) { + DHLOGE("lowLatencySwitchSet_ is oversize"); + return; + } + lowLatencySwitchSet_.insert(dhType); + DHLOGI("End EnableLowLatency dhType: %#X", dhType); +} + +void LowLatency::DisableLowLatency(DHType dhType) +{ + DHLOGI("Start DisableLowLatency dhType: %#X", dhType); + if (dhType <= DHType::UNKNOWN || dhType >= DHType::MAX_DH) { + DHLOGE("DHType is invalid, dhType: %" PRIu32, (uint32_t)dhType); + return; + } + lowLatencySwitchSet_.erase(dhType); + if (lowLatencySwitchSet_.empty()) { + DHLOGD("Close LowLatency dhType: %#X", dhType); + + auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance(); + // to restore normal latency mode: value = 1 + rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_DISABLE, + {{KEY, PKG_NAME}}); + } + DHLOGI("End DisableLowLatency dhType: %#X", dhType); +} + +void LowLatency::CloseLowLatency() +{ + DHLOGI("Shutdown LowLatency"); + lowLatencySwitchSet_.clear(); + auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance(); + // to restore normal latency mode: value = 1 + rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_DISABLE, + {{KEY, PKG_NAME}}); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp new file mode 100644 index 00000000..46cda102 --- /dev/null +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "constants.h" +#include "dh_utils_tool.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "low_latency_listener.h" + +namespace OHOS { +namespace DistributedHardware { +void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& message) +{ + if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { + DHLOGE("Topic is invalid, topic: %" PRIu32, (uint32_t)topic); + return; + } + if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { + DHLOGE("Message is invalid"); + return; + } + nlohmann::json jsonObj = nlohmann::json::parse(message, nullptr, false); + if (jsonObj.is_discarded()) { + DHLOGE("jsonStr parse failed"); + return; + } + if (!IsUint32(jsonObj, DH_TYPE)) { + DHLOGE("The DH_TYPE key is invalid"); + return; + } + if (!IsBool(jsonObj, LOW_LATENCY_ENABLE)) { + DHLOGE("The LOW_LATENCY_ENABLE key is invalid"); + return; + } + DHType dhType = jsonObj[DH_TYPE]; + bool isEnable = jsonObj[LOW_LATENCY_ENABLE]; + +#ifdef DHARDWARE_LOW_LATENCY + isEnable ? LowLatency::GetInstance().EnableLowLatency(dhType) : LowLatency::GetInstance().DisableLowLatency(dhType); +#endif +} + +sptr LowLatencyListener::AsObject() +{ + return nullptr; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/publisher/publisher.cpp b/services/distributedhardwarefwkservice/src/publisher/publisher.cpp index 0ce8172b..199637b7 100644 --- a/services/distributedhardwarefwkservice/src/publisher/publisher.cpp +++ b/services/distributedhardwarefwkservice/src/publisher/publisher.cpp @@ -23,7 +23,8 @@ Publisher::Publisher() : publisherItems_({ { DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, std::make_shared(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO) }, { DHTopic::TOPIC_STOP_DSCREEN, std::make_shared(DHTopic::TOPIC_STOP_DSCREEN) }, - { DHTopic::TOPIC_DEV_OFFLINE, std::make_shared(DHTopic::TOPIC_DEV_OFFLINE) } + { DHTopic::TOPIC_DEV_OFFLINE, std::make_shared(DHTopic::TOPIC_DEV_OFFLINE) }, + { DHTopic::TOPIC_LOW_LATENCY, std::make_shared(DHTopic::TOPIC_LOW_LATENCY) }, }) { } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn index c7981ec7..bdcb43d5 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn @@ -29,6 +29,7 @@ ohos_fuzztest("ComponentmanagerFuzzTest") { "${services_path}/distributedhardwarefwkservice/include/componentmanager", "${services_path}/distributedhardwarefwkservice/include/resourcemanager", "${services_path}/distributedhardwarefwkservice/include/utils", + "${services_path}/distributedhardwarefwkservice/include/lowlatency", "${common_path}/utils/include", "${common_path}/log/include", "//third_party/json/include", diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/BUILD.gn index ac41e439..754d045a 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/BUILD.gn @@ -33,6 +33,7 @@ config("module_private_config") { "${services_path}/distributedhardwarefwkservice/include/resourcemanager", "${services_path}/distributedhardwarefwkservice/include/versionmanager", "${services_path}/distributedhardwarefwkservice/include/utils", + "${services_path}/distributedhardwarefwkservice/include/lowlatency", "${common_path}/utils/include", "${common_path}/log/include", "//third_party/json/include", diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 789d4a80..f7c9598d 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -27,6 +27,7 @@ ohos_shared_library("distributedhardwareutils") { "include", "include/log", "include/eventbus", + "//third_party/json/include", ] sources = [ diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index a81b74f0..7abbbad6 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -18,6 +18,8 @@ #include +#include "nlohmann/json.hpp" + #include "device_type.h" namespace OHOS { @@ -40,6 +42,10 @@ DeviceInfo GetLocalDeviceInfo(); std::string GetDeviceIdByUUID(const std::string &uuid); std::string Sha256(const std::string& string); + +bool IsUint32(const nlohmann::json& jsonObj, const std::string& key); + +bool IsBool(const nlohmann::json& jsonObj, const std::string& key); } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 8b49ad54..38366ff7 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -126,5 +126,17 @@ DeviceInfo GetLocalDeviceInfo() devInfo.deviceType = info->deviceTypeId; return devInfo; } + +bool IsUint32(const nlohmann::json& jsonObj, const std::string& key) +{ + bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT32_MAX; + return res; +} + +bool IsBool(const nlohmann::json& jsonObj, const std::string& key) +{ + bool res = jsonObj.contains(key) && jsonObj[key].is_boolean(); + return res; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 7c1e91c3e5b1ce3b68b01d5451d018c6d3b8a60b Mon Sep 17 00:00:00 2001 From: tangfan Date: Thu, 10 Nov 2022 15:41:29 +0800 Subject: [PATCH 2/2] add low latency in dhfwk Signed-off-by: tangfan --- .../include/lowlatency/low_latency.h | 2 ++ .../src/lowlatency/low_latency.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h b/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h index 7000be84..8ee90f85 100644 --- a/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h +++ b/services/distributedhardwarefwkservice/include/lowlatency/low_latency.h @@ -16,6 +16,7 @@ #ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_H #define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_H +#include #include #include "device_type.h" @@ -36,6 +37,7 @@ private: private: std::unordered_set lowLatencySwitchSet_; + std::mutex lowLatencyMutex_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp index 5fe7c246..c75af690 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp @@ -41,6 +41,7 @@ void LowLatency::EnableLowLatency(DHType dhType) DHLOGE("DHType is invalid, dhType: %" PRIu32, (uint32_t)dhType); return; } + std::lock_guard lock(lowLatencyMutex_); DHLOGI("lowLatencySwitchSet size: %d", lowLatencySwitchSet_.size()); if (lowLatencySwitchSet_.empty()) { DHLOGD("Open LowLatency dhType: %#X", dhType); @@ -64,6 +65,7 @@ void LowLatency::DisableLowLatency(DHType dhType) DHLOGE("DHType is invalid, dhType: %" PRIu32, (uint32_t)dhType); return; } + std::lock_guard lock(lowLatencyMutex_); lowLatencySwitchSet_.erase(dhType); if (lowLatencySwitchSet_.empty()) { DHLOGD("Close LowLatency dhType: %#X", dhType); @@ -79,6 +81,7 @@ void LowLatency::DisableLowLatency(DHType dhType) void LowLatency::CloseLowLatency() { DHLOGI("Shutdown LowLatency"); + std::lock_guard lock(lowLatencyMutex_); lowLatencySwitchSet_.clear(); auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance(); // to restore normal latency mode: value = 1 -- Gitee