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 6, 2024
1 parent 2b85095 commit bc935be
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 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,27 +285,31 @@ 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();

leave_critical_section(flags);
fds->revents |= revents;
if ((fds->revents & (POLLERR | POLLHUP)) != 0)
{
/* Error or Hung up, clear POLLOUT event */

if ((fds->revents != 0 || (fds->events & POLLALWAYS) != 0) &&
fds->cb != NULL)
{
finfo("Report events: %08" PRIx32 "\n", fds->revents);
fds->cb(fds);
fds->revents &= ~POLLOUT;
}

leave_critical_section(flags);

if ((fds->events & POLLALWAYS) != 0 &&
fds->cb != NULL)
{
finfo("Report events: %08" PRIx32 "\n", fds->revents);
fds->cb(fds);
}
}
}
}
Expand Down

0 comments on commit bc935be

Please sign in to comment.