xiaoxiang781216 commented on code in PR #19596:
URL: https://github.com/apache/nuttx/pull/19596#discussion_r3697653883


##########
drivers/sensors/sensor.c:
##########
@@ -1177,12 +1248,40 @@ static int sensor_poll(FAR struct file *filep,
       fds->priv = filep;
       if (lower->ops->fetch)
         {
-          /* Always return POLLIN for fetch only sensor: the data is read
-           * from the device on demand by sensor_read(), so there is never
-           * anything to wait for.
+          /* A fetch() only sensor is read from the device on demand, so it
+           * is always ready unless this subscriber asked for a rate, in
+           * which case it becomes ready once per interval and
+           * sensor_fetch_worker() is what wakes the poll.
+           */
+
+#ifdef CONFIG_SCHED_LPWORK
+          if (user->state.interval == UINT32_MAX)
+            {
+              eventset |= POLLIN;
+            }
+          else
+            {
+              uint64_t now = sensor_get_timestamp();
+              uint64_t elapsed = now - user->fetched;
+
+              if (elapsed >= user->state.interval)
+                {
+                  user->fetched = now;
+                  eventset |= POLLIN;
+                }
+              else
+                {
+                  work_queue(LPWORK, &user->work, sensor_fetch_worker, user,

Review Comment:
   should we avoid the work queue? the benefit from fetch is avoiding the work 
or thread.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to