mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-31 21:03:10 +02:00
wakeup: Fix g_wakeup_acknowledge if signal comes in
It's not very likely, but there is a small chance that an incoming signal could disturb the non-blocking read calls in g_wakeup_acknowledge, leading to a subsequent spurious wake up. This commit addresses the problem by doing the usual EINTR loop (which is already present on the write side incidentally)
This commit is contained in:
parent
24f5711287
commit
7bbd4328f6
@ -207,20 +207,25 @@ g_wakeup_get_pollfd (GWakeup *wakeup,
|
|||||||
void
|
void
|
||||||
g_wakeup_acknowledge (GWakeup *wakeup)
|
g_wakeup_acknowledge (GWakeup *wakeup)
|
||||||
{
|
{
|
||||||
/* read until it is empty */
|
int res;
|
||||||
|
|
||||||
if (wakeup->fds[1] == -1)
|
if (wakeup->fds[1] == -1)
|
||||||
{
|
{
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
|
|
||||||
/* eventfd() read resets counter */
|
/* eventfd() read resets counter */
|
||||||
read (wakeup->fds[0], &value, sizeof (value));
|
do
|
||||||
|
res = read (wakeup->fds[0], &value, sizeof (value));
|
||||||
|
while (G_UNLIKELY (res == -1 && errno == EINTR));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
while (read (wakeup->fds[0], &value, sizeof (value)) == sizeof (value));
|
/* read until it is empty */
|
||||||
|
do
|
||||||
|
res = read (wakeup->fds[0], &value, sizeof (value));
|
||||||
|
while (res == sizeof (value) || G_UNLIKELY (res == -1 && errno == EINTR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user