summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Serban <mihai.serban@intel.com>2016-01-30 14:46:47 +0200
committerMihai Serban <mihai.serban@intel.com>2016-01-30 14:50:46 +0200
commit30688bbe0fe1b07407c033d07ed7e3d49a9fb22c (patch)
treedb8c74e0cedaa31a9c37b2b1d3afd7097c2eb747
parent017e5df408ad372efd8897eb24575d69a824281e (diff)
downloadintel-30688bbe0fe1b07407c033d07ed7e3d49a9fb22c.tar.gz
sensors: use Autolock instead of mutex methods
BUG=none Change-Id: I2033254032a0d8bdf1bd2342920ca8061c282722 Signed-off-by: Mihai Serban <mihai.serban@intel.com>
-rw-r--r--peripheral/sensors/mraa/SensorsHAL.cpp46
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;