It's more efficient than creating and destroying a new source for every dispatch and it simplifies the code.
Created attachment 264130 [details] Patch
Comment on attachment 264130 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=264130&action=review > Source/WTF/wtf/glib/RunLoopGLib.cpp:146 > stop(); > + g_source_destroy(m_source.get()); Is stop() still bringing anything here, given that the source is destroyed afterwards? > Source/WTF/wtf/glib/RunLoopGLib.cpp:152 > + gint64 current = g_get_monotonic_time(); > + g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? current + m_fireInterval.count() : current); I'd advise special-casing the 0-microsecond delay here, which is the most common. > gint64 delay = 0; > if (m_fireInterval.count()) > delay = g_get_monotonic_time() + m_fireInterval.count() > g_source_set_ready_time(m_source.get(), delay); That way you avoid querying the monotonic time for most cases, and 0 delay still means 'dispatch ASAP' in GLib. > Source/WTF/wtf/glib/RunLoopGLib.cpp:157 > + stop(); Is stop() useful here? The source's ready time is updated afterwards anyway.
(In reply to comment #2) > Comment on attachment 264130 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=264130&action=review > > > Source/WTF/wtf/glib/RunLoopGLib.cpp:146 > > stop(); > > + g_source_destroy(m_source.get()); > > Is stop() still bringing anything here, given that the source is destroyed > afterwards? Nope, it can be just removed. > > Source/WTF/wtf/glib/RunLoopGLib.cpp:152 > > + gint64 current = g_get_monotonic_time(); > > + g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? current + m_fireInterval.count() : current); > > I'd advise special-casing the 0-microsecond delay here, which is the most > common. Ok. > > gint64 delay = 0; > > if (m_fireInterval.count()) > > delay = g_get_monotonic_time() + m_fireInterval.count() > > g_source_set_ready_time(m_source.get(), delay); > > That way you avoid querying the monotonic time for most cases, and 0 delay > still means 'dispatch ASAP' in GLib. Ah, right, I guess we can do this too g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? g_get_monotonic_time() + m_fireInterval.count() : 0); > > Source/WTF/wtf/glib/RunLoopGLib.cpp:157 > > + stop(); > > Is stop() useful here? The source's ready time is updated afterwards anyway. Nope, it's also useless
Committed r191728: <http://trac.webkit.org/changeset/191728>
Re-opened since this is blocked by bug 150668
Created attachment 264389 [details] Patch for landing Found the problem of the timeouts in the bots. I was cancelling the persistent source in RunLoop:stop(). In case of nested main loop, if there are pedning tasks in the parent loop, the source is invalidated and the pending tasks are never done. We don't really need to cancel the source on stop, since the main loop will be stopped anyway and the main context won't process more sources. So, this patch simply removes the set_ready_time to -1 line in RunLoop::stop()
Committed r191786: <http://trac.webkit.org/changeset/191786>