Merge "libsensors: fix poll event that would use 100% CPU"
diff --git a/libsensors/IioSensorBase.cpp b/libsensors/IioSensorBase.cpp
index 999bf97..5e0eddf 100644
--- a/libsensors/IioSensorBase.cpp
+++ b/libsensors/IioSensorBase.cpp
@@ -51,7 +51,7 @@
       mIioSysfsChanFp(NULL),
       mLock(PTHREAD_MUTEX_INITIALIZER)
 {
-    ALOGD("%s(): dev_name=%s", __func__, dev_name);
+    ALOGV("%s(): dev_name=%s", __func__, dev_name);
     mPendingEvent.version = sizeof(sensors_event_t);
     memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
     if (!mDataFd)
diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp
index 806e437..2ef2b98 100644
--- a/libsensors/LightSensor.cpp
+++ b/libsensors/LightSensor.cpp
@@ -29,6 +29,6 @@
 }
 
 void LightSensor::handleData(int value) {
-    ALOGI("LightSensor::handleData value %d", value);
+    ALOGV("LightSensor::handleData value %d", value);
     mPendingEvent.light = value;
 }
diff --git a/libsensors/PressureSensor.cpp b/libsensors/PressureSensor.cpp
index c60e9f7..504d2cd 100644
--- a/libsensors/PressureSensor.cpp
+++ b/libsensors/PressureSensor.cpp
@@ -35,6 +35,6 @@
 }
 
 void PressureSensor::handleData(int value) {
-    ALOGD("PressureSensor::handleData value %d", value);
+    ALOGV("PressureSensor::handleData value %d", value);
     mPendingEvent.pressure = value * PRESSURE_HECTO_PA;
 }
diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp
index 0435145..b904a00 100644
--- a/libsensors/SensorBase.cpp
+++ b/libsensors/SensorBase.cpp
@@ -41,7 +41,7 @@
     : mDevName(dev_name), mDataName(data_name),
       mDevFd(-1), mDataFd(-1)
 {
-    ALOGD("%s(): dev_name=%s", __func__, dev_name);
+    ALOGV("%s(): dev_name=%s", __func__, dev_name);
     if (mDataName) {
         mDataFd = openInput(mDataName);
     }
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index 19fcd6a..33bc9fc 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -239,20 +239,21 @@
     int nbEvents = 0;
     int n = 0;
     int polltime = -1;
-
     do {
-        // see if we have some leftover from the last poll()
         for (int i=0 ; count && i<numSensorDrivers ; i++) {
             SensorBase* const sensor(mSensors[i]);
+            // See if we have some pending events from the last poll()
             if ((mPollFds[i].revents & POLLIN) || (sensor->hasPendingEvents())) {
                 int nb;
                 if (i == compass) {
-                    nb = ((MPLSensor*) sensor)->readCompassEvents(data, count);
-                    continue;
+                    /* result is hardcoded to 0 */
+                    ((MPLSensor*) sensor)->readCompassEvents(NULL, count);
+                    nb = ((MPLSensor*) mSensors[mpl])->executeOnData(data, count);
                 }
                 else if (i == mpl) {
-                    nb = sensor->readEvents(data, count);
-                    continue;
+                    /* result is hardcoded to 0 */
+                    sensor->readEvents(NULL, count);
+                    nb = ((MPLSensor*) mSensors[mpl])->executeOnData(data, count);
                 }
                 else {
                     nb = sensor->readEvents(data, count);
@@ -266,25 +267,11 @@
                 data += nb;
             }
         }
-        int nb = ((MPLSensor*) mSensors[mpl])->executeOnData(data, count);
-        if (nb > 0) {
-            count -= nb;
-            nbEvents += nb;
-            data += nb;
-            mPollFds[mpl].revents = 0;
-            mPollFds[compass].revents = 0;
-        }
-
         if (count) {
-            // we still have some room, so try to see if we can get
-            // some events immediately or just wait if we don't have
-            // anything to return
-            int i;
-
             do {
                 n = poll(mPollFds, numFds, nbEvents ? 0 : polltime);
             } while (n < 0 && errno == EINTR);
-            if (n<0) {
+            if (n < 0) {
                 ALOGE("poll() failed (%s)", strerror(errno));
                 return -errno;
             }