From a42b3ba35a5f692a9af42f1065530ea5f98d351b Mon Sep 17 00:00:00 2001 From: Cosmin Tanislav Date: Sat, 19 Feb 2022 23:34:29 +0200 Subject: [PATCH] sensors: Fix locking around setOperationMode and activate Change-Id: I9a09f45f012662c8f92fa40da3a4b9dd691a1b2c --- sensors/Sensor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sensors/Sensor.cpp b/sensors/Sensor.cpp index 2b8e1aa..dcf5b75 100644 --- a/sensors/Sensor.cpp +++ b/sensors/Sensor.cpp @@ -83,8 +83,8 @@ void Sensor::batch(int32_t samplingPeriodNs) { } void Sensor::activate(bool enable) { + std::lock_guard lock(mRunMutex); if (mIsEnabled != enable) { - std::unique_lock lock(mRunMutex); mIsEnabled = enable; mWaitCV.notify_all(); } @@ -158,8 +158,8 @@ std::vector Sensor::readEvents() { } void Sensor::setOperationMode(OperationMode mode) { + std::lock_guard lock(mRunMutex); if (mMode != mode) { - std::unique_lock lock(mRunMutex); mMode = mode; mWaitCV.notify_all(); }