diff options
author | Mihai Serban <mihai.serban@intel.com> | 2016-02-03 00:09:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-03 00:09:13 +0000 |
commit | d0bf08cd5e170666de6114d981a75adc21a13d3d (patch) | |
tree | 0853ffccee9675d13384731c82ed61d765622fc5 | |
parent | 0be6534f03823dea5ba20e3b529a1fc21b9646da (diff) | |
parent | 30688bbe0fe1b07407c033d07ed7e3d49a9fb22c (diff) | |
download | intel-d0bf08cd5e170666de6114d981a75adc21a13d3d.tar.gz |
sensors: use Autolock instead of mutex methods
am: 30688bbe0f
* commit '30688bbe0fe1b07407c033d07ed7e3d49a9fb22c':
sensors: use Autolock instead of mutex methods
-rw-r--r-- | peripheral/sensors/mraa/SensorsHAL.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/peripheral/sensors/mraa/SensorsHAL.cpp b/peripheral/sensors/mraa/SensorsHAL.cpp index eebcd45..4c9238e 100644 --- a/peripheral/sensors/mraa/SensorsHAL.cpp +++ b/peripheral/sensors/mraa/SensorsHAL.cpp @@ -193,31 +193,31 @@ int SensorContext::pollEvents(sensors_event_t *data, int count) { return nfds; } - mutex.lock(); - for(i = 0; i < nfds && returnedEvents < count; i++) { - if (ev[i].events == EPOLLIN) { - sensorIndex = ev[i].data.u32; - if ((sensorIndex < 0) || (sensorIndex > sensorsNum)) { - ALOGE("%s: Invalid sensor index", __func__); - mutex.unlock(); - return -1; - } - - if (sensors[sensorIndex] == nullptr) { - /* The sensor might have been deactivated by another thread */ - continue; - } - - /* - * The read operation might fail if the data is read by another - * pollEvents call executed by another thread. - */ - if (sensors[sensorIndex]->readOneEvent(data + returnedEvents)) { - returnedEvents++; + { // Autolock scope + android::Mutex::Autolock autolock(mutex); + for(i = 0; i < nfds && returnedEvents < count; i++) { + if (ev[i].events == EPOLLIN) { + sensorIndex = ev[i].data.u32; + if ((sensorIndex < 0) || (sensorIndex > sensorsNum)) { + ALOGE("%s: Invalid sensor index", __func__); + return -1; + } + + if (sensors[sensorIndex] == nullptr) { + /* The sensor might have been deactivated by another thread */ + continue; + } + + /* + * The read operation might fail if the data is read by another + * pollEvents call executed by another thread. + */ + if (sensors[sensorIndex]->readOneEvent(data + returnedEvents)) { + returnedEvents++; + } } } - } - mutex.unlock(); + } // Autolock scope if (returnedEvents > 0) { return returnedEvents; |