From dc8cfae3b22f7fa94a55f9f01de466b9c85e4069 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 15 Jan 2025 16:17:29 +0800 Subject: [PATCH] Modified branch differences Signed-off-by: li-yaoyao777 --- frameworks/native/include/sensor_agent_proxy.h | 1 + frameworks/native/src/sensor_agent_proxy.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index 5bac0b3b..ed1a89d5 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -67,6 +67,7 @@ private: int64_t reportInterval_ = -1; std::map> subscribeMap_; std::map> unsubscribeMap_; + static std::mutex createChannelMutex_; }; #define SENSOR_AGENT_IMPL OHOS::DelayedSingleton::GetInstance() diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index cf7a43f1..3fa993b2 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -38,6 +38,7 @@ int32_t sensorInfoCount_ = 0; #define SEN_CLIENT SensorServiceClient::GetInstance() std::recursive_mutex SensorAgentProxy::subscribeMutex_; std::mutex SensorAgentProxy::chanelMutex_; +std::mutex SensorAgentProxy::createChannelMutex_; SensorAgentProxy::SensorAgentProxy() : dataChannel_(new (std::nothrow) SensorDataChannel()) @@ -250,6 +251,7 @@ int32_t SensorAgentProxy::SubscribeSensor(int32_t sensorId, const SensorUser *us SEN_HILOGE("sensorId is invalid, %{public}d", sensorId); return PARAMETER_ERROR; } + std::lock_guard createChannelLock(createChannelMutex_); int32_t ret = CreateSensorDataChannel(); if (ret != ERR_OK) { SEN_HILOGE("Create sensor data chanel failed"); @@ -297,6 +299,7 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * unsubscribeMap_.erase(sensorId); } } + std::lock_guard createChannelLock(createChannelMutex_); if (IsSubscribeMapEmpty()) { int32_t ret = DestroySensorDataChannel(); if (ret != ERR_OK) { -- Gitee