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:
commit
9ec6c4dcf7
1 changed files with 12 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue