OSDN Git Service

GMIN-3044: Fix a few edge cases in filtering code
[android-x86/hardware-intel-libsensors.git] / control.c
index 8a4725c..3a827ae 100644 (file)
--- a/control.c
+++ b/control.c
@@ -558,6 +558,13 @@ int sensor_activate(int s, int enabled)
                                close(dev_fd);
                                device_fd[dev_num] = -1;
                        }
+
+               /* If we recorded a trail of samples for filtering, delete it */
+               if (sensor_info[s].history) {
+                       free(sensor_info[s].history);
+                       sensor_info[s].history = NULL;
+                       sensor_info[s].history_size = 0;
+               }
                return 0;
        }
 
@@ -838,9 +845,14 @@ static int get_poll_wait_timeout (void)
 
        ms_to_wait = (target_ts - get_timestamp()) / 1000000;
 
-       /* If the target timestamp is already behind us, don't wait */
-       if (ms_to_wait < 1)
-               return 0;
+       /*
+        * If the target timestamp is very close or already behind us, wait
+        * nonetheless for a millisecond in order to a) avoid busy loops, and
+        * b) give a chance for the driver to report data before we repeat the
+        * last received sample.
+        */
+       if (ms_to_wait <= 0)
+               return 1;
 
        return ms_to_wait;
 }