GNOME Bugzilla – Bug 750206
wrong if condition of g_wake_up_acknowledge in g_main_context_check()
Last modified: 2016-04-21 12:19:59 UTC
In g_main_context_check(param1, param2, GPollFD *fds, param4), the third param fds points to the results of poll(), where revents are modified by poll(). Near line 3599, it comes: if (context->wake_up_rec.revents) g_wakeup_acknowledge (context->wakeup); before near line 3613: while (pollrec && i < n_fds) ... // write revents back to pollrecs. If a wakeup exists, it will modify directly the revents in fds in the poll(), rather than the revents of pollrec. As a result, wake_up_rec.revents (a pollrec) stays still 0 filled, g_wakeup_acknowledge would not be called. The whole system can still run, though g_wakeup_acknowledge isn't called in time(I mean exactly after the wakeup exists), the "while" loop near line 3613 will then modify wake_up_rec(a pollrec), and the poll() during next g_main_context_iteration will not block as the fd used for wakeup is still readable, as wake_up_rec.revents is not 0 filled during the second g_main_context_check, g_wakeup_acknowledge will be called and the whole story of wakeup ends here. However, as we can see, redundant one loop of g_main_context_iteration reduce performance. In my opinion, the problem can be solved by either: 1. remove if condition of g_wakeup_acknowledge, just like what version 2.28.8 does; or: 2. move if condition and g_wakeup_acknowledge to after the "while" loop near line 3613.
Thanks for taking the time to report this and an accurate analysis. Bug #761102 has a patch for this. *** This bug has been marked as a duplicate of bug 761102 ***