From b267f648d936902e5cad679f2da575bad8bcd1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Sat, 29 Jul 2017 08:12:40 +0000 Subject: [PATCH] glib/gpoll W32: trust WFMOE() return value WaitForMultipleObjectsEx() returns the index of the *first* handle that triggered the wakeup, and promises that all handles with lower index are still inactive. Therefore, don't check them, only check the handles with higher index. This removes the need of rearranging the handles (and, now, handle_to_fd) array, it's enough to take a pointer to the next item and use it as a new, shorter array. https://bugzilla.gnome.org/show_bug.cgi?id=785468 --- glib/gpoll.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/glib/gpoll.c b/glib/gpoll.c index 9ebb10437..06ba70543 100644 --- a/glib/gpoll.c +++ b/glib/gpoll.c @@ -226,15 +226,16 @@ poll_rest (GPollFD *msg_fd, */ if (timeout == 0 && nhandles > 1) { - /* Remove the handle that fired */ - int i; - for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) - { - handles[i-1] = handles[i]; - handle_to_fd[i-1] = handle_to_fd[i]; - } - nhandles--; - recursed_result = poll_rest (NULL, handles, handle_to_fd, nhandles, 0); + /* Poll the handles with index > ready */ + HANDLE *shorter_handles; + GPollFD **shorter_handle_to_fd; + gint shorter_nhandles; + + shorter_handles = &handles[ready - WAIT_OBJECT_0 + 1]; + shorter_handle_to_fd = &handle_to_fd[ready - WAIT_OBJECT_0 + 1]; + shorter_nhandles = nhandles - (ready - WAIT_OBJECT_0 + 1); + + recursed_result = poll_rest (NULL, shorter_handles, shorter_handle_to_fd, shorter_nhandles, 0); return (recursed_result == -1) ? -1 : 1 + recursed_result; } return 1;