From 28a056309801ee29191b16db8b0bd1838291a0eb Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 4 Oct 2023 14:00:48 -0700 Subject: [PATCH] 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. --- glib/gwakeup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glib/gwakeup.c b/glib/gwakeup.c index 1674304f0..fbacab220 100644 --- a/glib/gwakeup.c +++ b/glib/gwakeup.c @@ -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 {