Skip to content

Commit

Permalink
fs/vfs/fs_poll.c: Only enter critical section when actually setting r…
Browse files Browse the repository at this point in the history
…events

This is an optimization.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Nov 7, 2024
1 parent 27ee0b4 commit 5996d97
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions fs/vfs/fs_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5996d97

Please sign in to comment.