gmain: don't pass the same fd to g_poll() multiple times
authorDan Winship <danw@gnome.org>
Tue, 13 Mar 2012 15:43:38 +0000 (11:43 -0400)
committerDan Winship <danw@gnome.org>
Wed, 29 Oct 2014 21:19:20 +0000 (17:19 -0400)
commitb3e3ed73864143e732c4d65441eaec086a3ab83e
tree8ca70fcef8d1f010a8d9970a8a5575b7b4104d26
parent66fc112c742f56f85fc34b458325e87df4cd78d0
gmain: don't pass the same fd to g_poll() multiple times

If a given fd is being polled by multiple sources, we used to pass it
multiple times to g_poll(), which is technically illegal (and not
supported by the select()-based fallback implementation of poll() in
gpoll.c), and also made it more likely that we'd exceed the maximum
number of pollfds.

Fix it to merge together "duplicate" GPollFDs. The easiest way to do
this involves re-sorting context->poll_records into fd order rather
than priority order. This means we now have to walk the entire pollrec
list for every g_main_context_query() and g_main_context_poll(),
rather than only walking the list up to the current max_priority.
However, this will only have a noticeable effect if you have tons of
GPollFDs, and we're already too slow in that case anyway because of
other O(n) operations that happen too often. So this shouldn't change
much (and the new poll API will eventually let us be cleverer).

Remove some win32-specific code which did the same thing (but was
O(n^2)).

https://bugzilla.gnome.org/show_bug.cgi?id=11059
glib/gmain.c
glib/gpoll.c
glib/tests/mainloop.c