GNOME Bugzilla – Bug 657729
modernise GMainLoop
Last modified: 2013-01-15 19:11:12 UTC
there are a few major changes that we should make to GMainLoop: - race-free with respect to signals - microsecond accurate - not O(n) - possibility of edge-triggered event sources Set the edge-triggered event sources thing aside for a moment since it's pretty extremely complicated, and consider the others. The biggest thing standing in the way is the existing GSource API. Mostly for two reasons: - each source expects to be polled each time (which is O(n)) - the source prepare function returns a time in milliseconds It seems that we could easily fix quite a lot of problems with two relatively minor API tweaks: 1) Add a g_source_set_wakeup_time() to allow setting an absolute monotonic time (in microseconds) at which the source should be woken up. 2) Allow the possibility of having the check/prepare functions given as NULL to mean "don't poll this source, but only dispatch it when one of its pollfds is ready or when its wakeup time has been reached". Internally, we would separate sources into two lists: those with the check/prepare functions and those without. On a mainloop iteration, we'd treat the sources with check/prepare in the same way as we do now, and completely fail to visit the ones without. Then we're only O(n) in terms of sources that use the old API.
(In reply to comment #0) > - not O(n) see also bug 143061 and bug 619329
I think I've asked this in the past, but it would be nice first step to gather some data on what n we are actually talking about here, in average apps.
From a practical standpoint, in our applications, it's quite small: no bigger than 20 at most, I'd say. Our O(n) behaviour is often cited for why people don't use GLib in some other types of applications, though.
I've pushed a few commits to the 'wip/source-api' branch in case anyone is interested.
Also see bug 156048
The API changes that this bug was intended to introduce have been merged to master. When we actually want to use this to support epoll, we can look at the other bug.