[glib] glib/gpoll W32: trust WFMOE() return value
- From: Руслан Ижбулатов <ruslanizhb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] glib/gpoll W32: trust WFMOE() return value
- Date: Tue, 1 Aug 2017 13:19:37 +0000 (UTC)
commit b267f648d936902e5cad679f2da575bad8bcd1ed
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date: Sat Jul 29 08:12:40 2017 +0000
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 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/glib/gpoll.c b/glib/gpoll.c
index 9ebb104..06ba705 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]