From 5996d975f86be99d30d5d6bded73f1c615e95805 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Wed, 6 Nov 2024 10:02:31 +0200 Subject: [PATCH] fs/vfs/fs_poll.c: Only enter critical section when actually setting revents This is an optimization. Signed-off-by: Jukka Laitinen --- fs/vfs/fs_poll.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index f043f57ee25b8..4c3ff5ebb8dea 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -275,6 +275,7 @@ void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset) { int i; FAR struct pollfd *fds; + pollevent_t revents; irqstate_t flags; DEBUGASSERT(afds != NULL && nfds >= 1); @@ -284,24 +285,29 @@ void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset) fds = afds[i]; if (fds != NULL) { - /* race condition protection when modifying fds->revents */ - - flags = enter_critical_section(); - /* The error event must be set in fds->revents */ - fds->revents |= eventset & (fds->events | POLLERR | POLLHUP); - if ((fds->revents & (POLLERR | POLLHUP)) != 0) + revents = eventset & (fds->events | POLLERR | POLLHUP); + if (revents != 0) { - /* Error or Hung up, clear POLLOUT event */ + /* race condition protection when modifying fds->revents */ - fds->revents &= ~POLLOUT; - } + flags = enter_critical_section(); + + fds->revents |= revents; + if ((fds->revents & (POLLERR | POLLHUP)) != 0) + { + /* Error or Hung up, clear POLLOUT event */ + + revents &= ~POLLOUT; + fds->revents &= ~POLLOUT; + } - leave_critical_section(flags); + leave_critical_section(flags); + } - if ((fds->revents != 0 || (fds->events & POLLALWAYS) != 0) && - fds->cb != NULL) + if (fds->cb != NULL && + (revents != 0 || (fds->events & POLLALWAYS))) { finfo("Report events: %08" PRIx32 "\n", fds->revents); fds->cb(fds);