From 143bbceef82ceda42cd6d8b1b59ace9e1451dae7 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Sat, 9 Nov 2024 11:38:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=E8=BD=AC=E6=8D=A2=E6=95=B0=E6=8D=AEcrash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuzhihuitmac Change-Id: Id6216c5397246282a787011cba60651da311c9b5 --- frameworks/js/napi/src/sensor_napi_utils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/js/napi/src/sensor_napi_utils.cpp b/frameworks/js/napi/src/sensor_napi_utils.cpp index f797e968..0780de8a 100644 --- a/frameworks/js/napi/src/sensor_napi_utils.cpp +++ b/frameworks/js/napi/src/sensor_napi_utils.cpp @@ -31,6 +31,7 @@ namespace Sensors { namespace { constexpr int32_t STRING_LENGTH_MAX = 64; } // namespace +static std::mutex g_sensorAttrListMutex; bool IsSameValue(const napi_env &env, const napi_value &lhs, const napi_value &rhs) { CALL_LOG_ENTER; @@ -321,6 +322,7 @@ bool ConvertToSensorData(const napi_env &env, sptr asyncCallb { CHKPF(asyncCallbackInfo); int32_t sensorTypeId = asyncCallbackInfo->data.sensorData.sensorTypeId; + std::lock_guard sensorAttrListLock(g_sensorAttrListMutex); CHKNCF(env, (g_sensorAttributeList.find(sensorTypeId) != g_sensorAttributeList.end()), "Invalid sensor type"); if (sensorTypeId == SENSOR_TYPE_ID_WEAR_DETECTION && asyncCallbackInfo->type == SUBSCRIBE_CALLBACK) { return ConvertToBodyData(env, asyncCallbackInfo, result);