This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d5819432b397e1f7be3d5b14f0886671f31be077
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Fri Mar 13 14:18:49 2026 +0800

    fs/epoll: add edge-triggered (EPOLLET) support
    
    In ET mode epoll_wait() reports an event once per new activity on the
    fd, instead of repeatedly while the condition holds.
    
    In epoll_teardown(), ET nodes keep their poll registration and stay in
    the setup list; only the notified flag and revents are reset, so only
    new driver events trigger later notifications.  LT behavior is
    unchanged.
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 fs/vfs/fs_epoll.c | 60 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 14 deletions(-)

diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c
index 3211fb09c00..b44916729b9 100644
--- a/fs/vfs/fs_epoll.c
+++ b/fs/vfs/fs_epoll.c
@@ -507,8 +507,13 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR 
struct epoll_event *evs,
   FAR epoll_node_t *tepn;
   FAR epoll_node_t *epn;
   int i = 0;
+  int ret;
 
-  nxrmutex_lock(&eph->lock);
+  ret = nxrmutex_lock(&eph->lock);
+  if (ret < 0)
+    {
+      return ret;
+    }
 
   list_for_every_entry_safe(&eph->setup, epn, tepn, epoll_node_t, node)
     {
@@ -519,28 +524,55 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR 
struct epoll_event *evs,
           continue;
         }
 
-      /* Teradown all the notified fd */
-
-      file_poll(epn->filep, &epn->pfd, false);
-      list_delete(&epn->node);
+      /* Edge-triggered mode: do not teardown the poll registration.
+       * Keep the node in the setup list so only NEW events from the
+       * driver will trigger notification. Reset notified flag so
+       * epoll_wait won't report stale events.
+       */
 
-      if (epn->pfd.revents != 0 && i < maxevents)
+      if ((epn->pfd.events & EPOLLET) != 0)
         {
-          evs[i].data     = epn->data;
-          evs[i++].events = epn->pfd.revents;
-          if ((epn->pfd.events & EPOLLONESHOT) != 0)
+          if (epn->pfd.revents != 0 && i < maxevents)
             {
-              list_add_tail(&eph->oneshot, &epn->node);
+              evs[i].data      = epn->data;
+              evs[i++].events  = epn->pfd.revents;
+              epn->notified    = false;
+              epn->pfd.revents = 0;
+              if ((epn->pfd.events & EPOLLONESHOT) != 0)
+                {
+                  file_poll(epn->filep, &epn->pfd, false);
+                  list_delete(&epn->node);
+                  list_add_tail(&eph->oneshot, &epn->node);
+                }
+            }
+        }
+      else
+        {
+          /* Level-triggered mode: teardown the poll and move to
+           * teardown list. epoll_setup will re-register and re-check.
+           */
+
+          file_poll(epn->filep, &epn->pfd, false);
+          list_delete(&epn->node);
+
+          if (epn->pfd.revents != 0 && i < maxevents)
+            {
+              evs[i].data     = epn->data;
+              evs[i++].events = epn->pfd.revents;
+              if ((epn->pfd.events & EPOLLONESHOT) != 0)
+                {
+                  list_add_tail(&eph->oneshot, &epn->node);
+                }
+              else
+                {
+                  list_add_tail(&eph->teardown, &epn->node);
+                }
             }
           else
             {
               list_add_tail(&eph->teardown, &epn->node);
             }
         }
-      else
-        {
-          list_add_tail(&eph->teardown, &epn->node);
-        }
     }
 
   nxrmutex_unlock(&eph->lock);

Reply via email to