dynamic_sensor: Don't hold mgr lock when operating sensor. am: 24ead9d84a

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/libhardware/+/16185557

Change-Id: I58f1a86b128abfe3212b2cf4eeb87198e0477d82
This commit is contained in:
Erik Staats 2021-11-04 16:16:42 +00:00 committed by Automerger Merge Worker
commit 9ec6c4dcf7

View file

@ -95,15 +95,18 @@ private:
// TF: int foo(sp<BaseSensorObject> obj);
template <typename TF>
int operateSensor(int handle, TF f) const {
std::lock_guard<std::mutex> lk(mLock);
const auto i = mMap.find(handle);
if (i == mMap.end()) {
return BAD_VALUE;
}
sp<BaseSensorObject> s = i->second.promote();
if (s == nullptr) {
// sensor object is already gone
return BAD_VALUE;
sp<BaseSensorObject> s;
{
std::lock_guard<std::mutex> lk(mLock);
const auto i = mMap.find(handle);
if (i == mMap.end()) {
return BAD_VALUE;
}
s = i->second.promote();
if (s == nullptr) {
// sensor object is already gone
return BAD_VALUE;
}
}
return f(s);
}