Bug 144732

Summary: [GTK] RunLoop constructor should properly retrieve or establish the thread-default GMainContext
Product: WebKit Reporter: Zan Dobersek <zan>
Component: New BugsAssignee: Zan Dobersek <zan>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cmarcelo, commit-queue
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Zan Dobersek 2015-05-07 01:54:34 PDT
[GTK] RunLoop constructor should properly retrieve or establish the thread-default GMainContext
Comment 1 Zan Dobersek 2015-05-07 02:06:22 PDT
Created attachment 252581 [details]
Patch
Comment 2 Carlos Garcia Campos 2015-05-07 02:21:01 PDT
Comment on attachment 252581 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=252581&action=review

> Source/WTF/wtf/gtk/RunLoopGtk.cpp:40
> +    GMainContext* runLoopContext = g_main_context_get_thread_default();
> +    if (!runLoopContext) {
> +        if (!isMainThread()) {
> +            m_mainContext = adoptGRef(g_main_context_new());

This could be simplified by using g_main_context_ref_thread_default(), because it ensures a main context is returned.

> Source/WTF/wtf/gtk/RunLoopGtk.cpp:41
> +            g_main_context_push_thread_default(m_mainContext.get());

I'm not sure about doing this here, I think it should be done before running the loop, and pop it after it quits. Doing it here, means that if a thread doesn't use a RunLoop, but something like RunLoop::isMain() is called, RunLoop::current() creates a new RunLoop for the thread and pushes a new main context.
Comment 3 Zan Dobersek 2015-05-07 02:56:58 PDT
Created attachment 252582 [details]
Patch
Comment 4 Carlos Garcia Campos 2015-05-07 09:52:12 PDT
Comment on attachment 252582 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=252582&action=review

> Source/WTF/wtf/gtk/RunLoopGtk.cpp:66
> +        g_main_context_push_thread_default(mainContext);

So, are we doing this also for the main thread?
Comment 5 Zan Dobersek 2015-05-07 23:54:58 PDT
Comment on attachment 252582 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=252582&action=review

>> Source/WTF/wtf/gtk/RunLoopGtk.cpp:66
>> +        g_main_context_push_thread_default(mainContext);
> 
> So, are we doing this also for the main thread?

Yes. g_main_context_push_thread_default() checks if the passed-in context is the global-default one, pushing a null pointer on the top of the stack in that case. That way g_main_context_get_thread_default() still returns a null pointer on the main thread.
Comment 6 Zan Dobersek 2015-05-14 00:52:38 PDT
Created attachment 253110 [details]
Patch
Comment 7 Zan Dobersek 2015-05-14 02:34:16 PDT
Comment on attachment 253110 [details]
Patch

Clearing flags on attachment: 253110

Committed r184333: <http://trac.webkit.org/changeset/184333>
Comment 8 Zan Dobersek 2015-05-14 02:34:23 PDT
All reviewed patches have been landed.  Closing bug.