wakeup: do single read when using eventfd()

Previously, this would loop as long as read() got the expected number of
bytes back, which is 8. That means every successful read() of the eventfd
would perform an additional syscall() as a followup.

This is not ideal because eventfd (unless used as an EFD_SEMAPHORE) will
reset the counter as part of the read(). So that means that we either do
an additional throw-away syscall() or potentially race against a producer
generating new events before this change.
This commit is contained in:
Christian Hergert 2023-10-04 14:00:48 -07:00
parent bd13ec30a9
commit de79831e3c

View File

@ -213,7 +213,8 @@ g_wakeup_acknowledge (GWakeup *wakeup)
{
uint64_t value;
while (read (wakeup->fds[0], &value, sizeof (value)) == sizeof (value));
/* eventfd() read resets counter */
read (wakeup->fds[0], &value, sizeof (value));
}
else
{