diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index de500da8fb75974c3e4f19d715e6ddf2730957af..0a956f50fea0c5b01fcadb8bf22332e7f366fdf3 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -244,11 +244,13 @@ int32_t SensorServiceClient::DestroyDataChannel() void SensorServiceClient::ReenableSensor() { CALL_LOG_ENTER; - std::lock_guard mapLock(mapMutex_); - for (const auto &it : sensorInfoMap_) { + { std::lock_guard clientLock(clientMutex_); - if (sensorServer_ != nullptr) { - sensorServer_->EnableSensor(it.first, it.second.GetSamplingPeriodNs(), it.second.GetMaxReportDelayNs()); + std::lock_guard mapLock(mapMutex_); + for (const auto &it : sensorInfoMap_) { + if (sensorServer_ != nullptr) { + sensorServer_->EnableSensor(it.first, it.second.GetSamplingPeriodNs(), it.second.GetMaxReportDelayNs()); + } } } if (!isConnected_) {