Changeset 109129 in webkit


Ignore:
Timestamp:
Feb 28, 2012 11:35:15 AM (12 years ago)
Author:
mario@webkit.org
Message:

[GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
https://bugs.webkit.org/show_bug.cgi?id=79496

Reviewed by Martin Robinson.

Source/JavaScriptCore:

Handle GMainLoop and GMainContext in GRefPtr, by calling
g_main_loop_(un)ref and g_main_context_(un)ref in the
implementation of the refGPtr and derefGPtr template functions.

  • wtf/gobject/GRefPtr.cpp:

(WTF::refGPtr):
(WTF):
(WTF::derefGPtr):

  • wtf/gobject/GRefPtr.h:

(WTF):

  • wtf/gobject/GTypedefs.h:

Source/WebCore:

Updated places where raw pointers to GMainLoop and GMainContext
were being used, replacing them with GRefPtr-based code.

  • platform/RunLoop.h:

(RunLoop):

  • platform/gtk/RunLoopGtk.cpp:

(WebCore::RunLoop::RunLoop):
(WebCore::RunLoop::~RunLoop):
(WebCore::RunLoop::mainLoop):
(WebCore::RunLoop::stop):
(WebCore::RunLoop::wakeUp):
(WebCore::RunLoop::TimerBase::start):

  • platform/network/soup/ResourceHandleSoup.cpp:

(WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::~WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::didFinishLoading):
(WebCore::WebCoreSynchronousLoader::run):

Source/WebKit2:

Updated places where raw pointers to GMainLoop and GMainContext
were being used, replacing them with GRefPtr-based code.

  • Platform/WorkQueue.h:

(WorkQueue):

  • Platform/gtk/WorkQueueGtk.cpp:

(WorkQueue::platformInitialize):
(WorkQueue::platformInvalidate):
(WorkQueue::workQueueThreadBody):
(WorkQueue::registerEventSourceHandler):
(WorkQueue::dispatchOnSource):

  • UIProcess/gtk/WebPopupMenuProxyGtk.cpp:

(WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk):
(WebKit::WebPopupMenuProxyGtk::showPopupMenu):
(WebKit::WebPopupMenuProxyGtk::shutdownRunLoop):

  • UIProcess/gtk/WebPopupMenuProxyGtk.h:

(WebPopupMenuProxyGtk):

Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r109105 r109129  
     12012-02-28  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
     4        https://bugs.webkit.org/show_bug.cgi?id=79496
     5
     6        Reviewed by Martin Robinson.
     7
     8        Handle GMainLoop and GMainContext in GRefPtr, by calling
     9        g_main_loop_(un)ref and g_main_context_(un)ref in the
     10        implementation of the refGPtr and derefGPtr template functions.
     11
     12        * wtf/gobject/GRefPtr.cpp:
     13        (WTF::refGPtr):
     14        (WTF):
     15        (WTF::derefGPtr):
     16        * wtf/gobject/GRefPtr.h:
     17        (WTF):
     18        * wtf/gobject/GTypedefs.h:
     19
    1202012-02-28  Yong Li  <yoli@rim.com>
    221
  • trunk/Source/JavaScriptCore/wtf/gobject/GRefPtr.cpp

    r95901 r109129  
    3636{
    3737    g_hash_table_unref(ptr);
     38}
     39
     40template <> GMainContext* refGPtr(GMainContext* ptr)
     41{
     42    if (ptr)
     43        g_main_context_ref(ptr);
     44    return ptr;
     45}
     46
     47template <> void derefGPtr(GMainContext* ptr)
     48{
     49    if (ptr)
     50        g_main_context_unref(ptr);
     51}
     52
     53template <> GMainLoop* refGPtr(GMainLoop* ptr)
     54{
     55    if (ptr)
     56        g_main_loop_ref(ptr);
     57    return ptr;
     58}
     59
     60template <> void derefGPtr(GMainLoop* ptr)
     61{
     62    if (ptr)
     63        g_main_loop_unref(ptr);
    3864}
    3965
  • trunk/Source/JavaScriptCore/wtf/gobject/GRefPtr.h

    r95901 r109129  
    202202template <> GHashTable* refGPtr(GHashTable* ptr);
    203203template <> void derefGPtr(GHashTable* ptr);
     204template <> GMainContext* refGPtr(GMainContext* ptr);
     205template <> void derefGPtr(GMainContext* ptr);
     206template <> GMainLoop* refGPtr(GMainLoop* ptr);
     207template <> void derefGPtr(GMainLoop* ptr);
    204208template <> GVariant* refGPtr(GVariant* ptr);
    205209template <> void derefGPtr(GVariant* ptr);
  • trunk/Source/JavaScriptCore/wtf/gobject/GTypedefs.h

    r107566 r109129  
    5252typedef struct _GInputStream GInputStream;
    5353typedef struct _GList GList;
     54typedef struct _GMainContext GMainContext;
     55typedef struct _GMainLoop GMainLoop;
    5456typedef struct _GPatternSpec GPatternSpec;
    5557typedef struct _GPollableOutputStream GPollableOutputStream;
  • trunk/Source/WebCore/ChangeLog

    r109125 r109129  
     12012-02-28  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
     4        https://bugs.webkit.org/show_bug.cgi?id=79496
     5
     6        Reviewed by Martin Robinson.
     7
     8        Updated places where raw pointers to GMainLoop and GMainContext
     9        were being used, replacing them with GRefPtr-based code.
     10
     11        * platform/RunLoop.h:
     12        (RunLoop):
     13        * platform/gtk/RunLoopGtk.cpp:
     14        (WebCore::RunLoop::RunLoop):
     15        (WebCore::RunLoop::~RunLoop):
     16        (WebCore::RunLoop::mainLoop):
     17        (WebCore::RunLoop::stop):
     18        (WebCore::RunLoop::wakeUp):
     19        (WebCore::RunLoop::TimerBase::start):
     20        * platform/network/soup/ResourceHandleSoup.cpp:
     21        (WebCoreSynchronousLoader):
     22        (WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
     23        (WebCore::WebCoreSynchronousLoader::~WebCoreSynchronousLoader):
     24        (WebCore::WebCoreSynchronousLoader::didFinishLoading):
     25        (WebCore::WebCoreSynchronousLoader::run):
     26
    1272012-02-28  Alok Priyadarshi  <alokp@chromium.org>
    228
  • trunk/Source/WebCore/platform/RunLoop.h

    r105552 r109129  
    3838#if PLATFORM(GTK)
    3939#include <wtf/gobject/GRefPtr.h>
    40 typedef struct _GSource GSource;
    41 typedef struct _GMainLoop GMainLoop;
    42 typedef struct _GMainContext GMainContext;
    43 typedef int gboolean;
    4440#endif
    4541
     
    158154    GMainLoop* mainLoop();
    159155private:
    160     GMainContext* m_runLoopContext;
    161     GMainLoop* m_runLoopMain;
     156    GRefPtr<GMainContext> m_runLoopContext;
     157    GRefPtr<GMainLoop> m_runLoopMain;
    162158#endif
    163159};
  • trunk/Source/WebCore/platform/gtk/RunLoopGtk.cpp

    r105475 r109129  
    3434RunLoop::RunLoop()
    3535{
     36    // g_main_context_default() doesn't add an extra reference.
    3637    m_runLoopContext = g_main_context_default();
    3738    ASSERT(m_runLoopContext);
    38     m_runLoopMain = g_main_loop_new(m_runLoopContext, FALSE);
     39    m_runLoopMain = adoptGRef(g_main_loop_new(m_runLoopContext.get(), FALSE));
    3940    ASSERT(m_runLoopMain);
    4041}
     
    4243RunLoop::~RunLoop()
    4344{
    44     if (m_runLoopMain) {
    45         if (g_main_loop_is_running(m_runLoopMain))
    46             g_main_loop_quit(m_runLoopMain);
    47         g_main_loop_unref(m_runLoopMain);
    48     }
    49 
    50     if (m_runLoopContext)
    51         g_main_context_unref(m_runLoopContext);
     45    if (m_runLoopMain && g_main_loop_is_running(m_runLoopMain.get()))
     46        g_main_loop_quit(m_runLoopMain.get());
    5247}
    5348
     
    5954GMainLoop* RunLoop::mainLoop()
    6055{
    61     return m_runLoopMain;
     56    return m_runLoopMain.get();
    6257}
    6358
    6459void RunLoop::stop()
    6560{
    66     g_main_loop_quit(m_runLoopMain);
     61    g_main_loop_quit(m_runLoopMain.get());
    6762}
    6863
     
    7873    g_source_set_priority(source.get(), G_PRIORITY_DEFAULT);
    7974    g_source_set_callback(source.get(), reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0);
    80     g_source_attach(source.get(), m_runLoopContext);
     75    g_source_attach(source.get(), m_runLoopContext.get());
    8176
    82     g_main_context_wakeup(m_runLoopContext);
     77    g_main_context_wakeup(m_runLoopContext.get());
    8378}
    8479
     
    118113    m_isRepeating = repeat;
    119114    g_source_set_callback(m_timerSource.get(), reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::timerFiredCallback), this, 0);
    120     g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext);
     115    g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext.get());
    121116}
    122117
  • trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp

    r107973 r109129  
    5757#include <sys/types.h>
    5858#include <unistd.h>
     59#include <wtf/gobject/GRefPtr.h>
    5960#include <wtf/text/CString.h>
    6061
     
    8788    Vector<char>& m_data;
    8889    bool m_finished;
    89     GMainLoop* m_mainLoop;
     90    GRefPtr<GMainLoop> m_mainLoop;
    9091};
    9192
     
    9697    , m_finished(false)
    9798{
    98     m_mainLoop = g_main_loop_new(0, false);
     99    m_mainLoop = adoptGRef(g_main_loop_new(0, false));
    99100}
    100101
    101102WebCoreSynchronousLoader::~WebCoreSynchronousLoader()
    102103{
    103     g_main_loop_unref(m_mainLoop);
    104104}
    105105
     
    116116void WebCoreSynchronousLoader::didFinishLoading(ResourceHandle*, double)
    117117{
    118     g_main_loop_quit(m_mainLoop);
     118    g_main_loop_quit(m_mainLoop.get());
    119119    m_finished = true;
    120120}
     
    129129{
    130130    if (!m_finished)
    131         g_main_loop_run(m_mainLoop);
     131        g_main_loop_run(m_mainLoop.get());
    132132}
    133133
  • trunk/Source/WebKit2/ChangeLog

    r109121 r109129  
     12012-02-28  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
     4        https://bugs.webkit.org/show_bug.cgi?id=79496
     5
     6        Reviewed by Martin Robinson.
     7
     8        Updated places where raw pointers to GMainLoop and GMainContext
     9        were being used, replacing them with GRefPtr-based code.
     10
     11        * Platform/WorkQueue.h:
     12        (WorkQueue):
     13        * Platform/gtk/WorkQueueGtk.cpp:
     14        (WorkQueue::platformInitialize):
     15        (WorkQueue::platformInvalidate):
     16        (WorkQueue::workQueueThreadBody):
     17        (WorkQueue::registerEventSourceHandler):
     18        (WorkQueue::dispatchOnSource):
     19        * UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
     20        (WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk):
     21        (WebKit::WebPopupMenuProxyGtk::showPopupMenu):
     22        (WebKit::WebPopupMenuProxyGtk::shutdownRunLoop):
     23        * UIProcess/gtk/WebPopupMenuProxyGtk.h:
     24        (WebPopupMenuProxyGtk):
     25
    1262012-02-28  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
    227
  • trunk/Source/WebKit2/Platform/WorkQueue.h

    r108119 r109129  
    4949#elif PLATFORM(GTK)
    5050#include "PlatformProcessIdentifier.h"
    51 typedef struct _GMainContext GMainContext;
    52 typedef struct _GMainLoop GMainLoop;
     51#include <wtf/gobject/GRefPtr.h>
    5352typedef gboolean (*GSourceFunc) (gpointer data);
    5453#endif
     
    172171
    173172    ThreadIdentifier m_workQueueThread;
    174     GMainContext* m_eventContext;
     173    GRefPtr<GMainContext> m_eventContext;
    175174    Mutex m_eventLoopLock;
    176     GMainLoop* m_eventLoop;
     175    GRefPtr<GMainLoop> m_eventLoop;
    177176    Mutex m_eventSourcesLock;
    178177    class EventSource;
  • trunk/Source/WebKit2/Platform/gtk/WorkQueueGtk.cpp

    r108119 r109129  
    104104void WorkQueue::platformInitialize(const char* name)
    105105{
    106     m_eventContext = g_main_context_new();
     106    m_eventContext = adoptGRef(g_main_context_new());
    107107    ASSERT(m_eventContext);
    108     m_eventLoop = g_main_loop_new(m_eventContext, FALSE);
     108    m_eventLoop = adoptGRef(g_main_loop_new(m_eventContext.get(), FALSE));
    109109    ASSERT(m_eventLoop);
    110110
     
    130130
    131131    if (m_eventLoop) {
    132         if (g_main_loop_is_running(m_eventLoop))
    133             g_main_loop_quit(m_eventLoop);
    134 
    135         g_main_loop_unref(m_eventLoop);
    136         m_eventLoop = 0;
    137     }
    138 
    139     if (m_eventContext) {
    140         g_main_context_unref(m_eventContext);
    141         m_eventContext = 0;
    142     }
     132        if (g_main_loop_is_running(m_eventLoop.get()))
     133            g_main_loop_quit(m_eventLoop.get());
     134        m_eventLoop.clear();
     135    }
     136
     137    m_eventContext.clear();
    143138}
    144139
     
    150145void WorkQueue::workQueueThreadBody()
    151146{
    152     g_main_loop_run(m_eventLoop);
     147    g_main_loop_run(m_eventLoop.get());
    153148}
    154149
     
    178173    }
    179174
    180     g_source_attach(dispatchSource.get(), m_eventContext);
     175    g_source_attach(dispatchSource.get(), m_eventContext.get());
    181176}
    182177
     
    207202                          reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
    208203
    209     g_source_attach(dispatchSource, m_eventContext);
     204    g_source_attach(dispatchSource, m_eventContext.get());
    210205}
    211206
  • trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp

    r101678 r109129  
    4242    , m_webView(webView)
    4343    , m_activeItem(-1)
    44     , m_runLoop(0)
    4544{
    4645}
     
    9796    // WebPageProxy expects the menu to run in a nested run loop, since it invalidates the
    9897    // menu right after calling WebPopupMenuProxy::showPopupMenu().
    99     m_runLoop = g_main_loop_new(0, FALSE);
     98    m_runLoop = adoptGRef(g_main_loop_new(0, FALSE));
    10099
    101100    GDK_THREADS_LEAVE();
    102     g_main_loop_run(m_runLoop);
     101    g_main_loop_run(m_runLoop.get());
    103102    GDK_THREADS_ENTER();
    104103
    105     g_main_loop_unref(m_runLoop);
    106     m_runLoop = 0;
     104    m_runLoop.clear();
    107105
    108106    g_signal_handler_disconnect(m_popup->platformMenu(), unmapHandler);
     
    121119void WebPopupMenuProxyGtk::shutdownRunLoop()
    122120{
    123     if (g_main_loop_is_running(m_runLoop))
    124         g_main_loop_quit(m_runLoop);
     121    if (g_main_loop_is_running(m_runLoop.get()))
     122        g_main_loop_quit(m_runLoop.get());
    125123}
    126124
  • trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h

    r95901 r109129  
    2424#include <WebCore/GtkPopupMenu.h>
    2525#include <WebCore/IntRect.h>
     26#include <wtf/gobject/GRefPtr.h>
    2627
    2728typedef struct _GMainLoop GMainLoop;
     
    5455    OwnPtr<WebCore::GtkPopupMenu> m_popup;
    5556    int m_activeItem;
    56     GMainLoop* m_runLoop;
     57    GRefPtr<GMainLoop> m_runLoop;
    5758};
    5859
Note: See TracChangeset for help on using the changeset viewer.