From 7292a456001fca528baa6334e58e53b7e0d23bba Mon Sep 17 00:00:00 2001 From: maan4 Date: Fri, 10 Jan 2025 22:33:08 +0800 Subject: [PATCH] =?UTF-8?q?[bug]=20=E5=88=9B=E5=BB=BA=E9=80=9A=E9=81=93?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=BC=95=E7=94=A8=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F=E9=81=BF=E5=85=8D=E9=80=9A=E9=81=93=E8=A2=AB?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E5=9C=BA=E6=99=AF=E9=94=80=E6=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: maan4 --- 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 5d58e112..e1e44219 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 f5d7368c..61cdfb01 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()) @@ -256,6 +257,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"); @@ -304,6 +306,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