Changeset 83281 in webkit


Ignore:
Timestamp:
Apr 8, 2011 3:35:28 AM (13 years ago)
Author:
Carlos Garcia Campos
Message:

2011-04-08 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Do not destroy WorkQueue event sources unless they have been cancelled
https://bugs.webkit.org/show_bug.cgi?id=57611

  • Platform/WorkQueue.h:
  • Platform/gtk/WorkQueueGtk.cpp: (WorkQueue::EventSource::EventSource): Remove unused member m_dispatchSource. (WorkQueue::EventSource::executeEventSource): Make it return void instead of boolean since we are always ignoring the return value. (WorkQueue::EventSource::performWork): Return FALSE from the callback only when the source has been cancelled (condition = 0) to make sure it's destroyed when the even source handler is unregistered. (WorkQueue::registerEventSourceHandler): Use GRefPtr for the source, to avoid leaking it. (WorkQueue::scheduleWorkOnSource): Receive the source callback as parameter so that it can be used by scheduleWorkOnTermination() too. (WorkQueue::scheduleWork): (WorkQueue::scheduleWorkAfterDelay): (WorkQueue::scheduleWorkOnTermination): Use scheduleWorkOnSource().
Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r83280 r83281  
     12011-04-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Do not destroy WorkQueue event sources unless they have been cancelled
     6        https://bugs.webkit.org/show_bug.cgi?id=57611
     7
     8        * Platform/WorkQueue.h:
     9        * Platform/gtk/WorkQueueGtk.cpp:
     10        (WorkQueue::EventSource::EventSource): Remove unused member
     11        m_dispatchSource.
     12        (WorkQueue::EventSource::executeEventSource): Make it return void
     13        instead of boolean since we are always ignoring the return value.
     14        (WorkQueue::EventSource::performWork): Return FALSE from the
     15        callback only when the source has been cancelled (condition = 0)
     16        to make sure it's destroyed when the even source handler is
     17        unregistered.
     18        (WorkQueue::registerEventSourceHandler): Use GRefPtr for the
     19        source, to avoid leaking it.
     20        (WorkQueue::scheduleWorkOnSource): Receive the source callback as
     21        parameter so that it can be used by scheduleWorkOnTermination() too.
     22        (WorkQueue::scheduleWork):
     23        (WorkQueue::scheduleWorkAfterDelay):
     24        (WorkQueue::scheduleWorkOnTermination): Use
     25        scheduleWorkOnSource().
     26
    1272011-04-08  Carlos Garcia Campos  <cgarcia@igalia.com>
    228
  • trunk/Source/WebKit2/Platform/WorkQueue.h

    r83280 r83281  
    5050typedef struct _GMainContext GMainContext;
    5151typedef struct _GMainLoop GMainLoop;
     52typedef gboolean (*GSourceFunc) (gpointer data);
    5253#endif
    5354
     
    168169    static void* startWorkQueueThread(WorkQueue*);
    169170    void workQueueThreadBody();
    170     void scheduleWorkOnSource(GSource*, PassOwnPtr<WorkItem>);
     171    void scheduleWorkOnSource(GSource*, PassOwnPtr<WorkItem>, GSourceFunc);
    171172
    172173    ThreadIdentifier m_workQueueThread;
  • trunk/Source/WebKit2/Platform/gtk/WorkQueueGtk.cpp

    r83280 r83281  
    11/*
     2 * Copyright (C) 2011 Igalia S.L.
    23 * Copyright (C) 2010 Apple Inc. All rights reserved.
    34 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
     
    3738class WorkQueue::EventSource {
    3839public:
    39     EventSource(GSource* dispatchSource, PassOwnPtr<WorkItem> workItem, WorkQueue* workQueue, GCancellable* cancellable)
    40         : m_dispatchSource(dispatchSource)
    41         , m_workItem(workItem)
     40    EventSource(PassOwnPtr<WorkItem> workItem, WorkQueue* workQueue, GCancellable* cancellable)
     41        : m_workItem(workItem)
    4242        , m_workQueue(workQueue)
    4343        , m_cancellable(cancellable)
     
    5252    }
    5353
    54     static gboolean executeEventSource(EventSource* eventSource)
     54    static void executeEventSource(EventSource* eventSource)
    5555    {
    5656        ASSERT(eventSource);
     
    5959            MutexLocker locker(queue->m_isValidMutex);
    6060            if (!queue->m_isValid)
    61                 return FALSE;
     61                return;
    6262        }
    6363
    6464        eventSource->m_workItem->execute();
    65 
    66         return TRUE;
    6765    }
    6866
     
    7573    static gboolean performWork(GSocket* socket, GIOCondition condition, EventSource* eventSource)
    7674    {
    77         if (!(condition & G_IO_IN) && !(condition & G_IO_HUP) && !(condition & G_IO_ERR))
     75        if (!(condition & G_IO_IN) && !(condition & G_IO_HUP) && !(condition & G_IO_ERR)) {
     76            // EventSource has been cancelled, return FALSE to destroy the source.
    7877            return FALSE;
    79 
    80 
    81         if (!executeEventSource(eventSource))
    82             return FALSE;
    83 
    84         if ((condition & G_IO_HUP) || (condition & G_IO_ERR))
    85             return FALSE;
    86 
     78        }
     79
     80        executeEventSource(eventSource);
    8781        return TRUE;
    8882    }
     
    10195   
    10296public:
    103     GSource* m_dispatchSource;
    10497    PassOwnPtr<WorkItem> m_workItem;
    10598    WorkQueue* m_workQueue;
     
    151144    ASSERT(socket);
    152145    GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new());
    153     GSource* dispatchSource = g_socket_create_source(socket.get(), static_cast<GIOCondition>(condition), cancellable.get());
    154     ASSERT(dispatchSource);
    155     EventSource* eventSource = new EventSource(dispatchSource, item, this, cancellable.get());
     146    GRefPtr<GSource> dispatchSource = adoptGRef(g_socket_create_source(socket.get(), static_cast<GIOCondition>(condition), cancellable.get()));
     147    ASSERT(dispatchSource);
     148    EventSource* eventSource = new EventSource(item, this, cancellable.get());
    156149    ASSERT(eventSource);
    157150
    158     g_source_set_callback(dispatchSource, reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWork),
     151    g_source_set_callback(dispatchSource.get(), reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWork),
    159152        eventSource, reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
    160153
     
    171164    }
    172165
    173     g_source_attach(dispatchSource, m_eventContext);
     166    g_source_attach(dispatchSource.get(), m_eventContext);
    174167}
    175168
     
    193186}
    194187
    195 void WorkQueue::scheduleWorkOnSource(GSource* dispatchSource, PassOwnPtr<WorkItem> item)
    196 {
    197     EventSource* eventSource = new EventSource(dispatchSource, item, this, 0);
    198 
    199     g_source_set_callback(dispatchSource,
    200                           reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce),
    201                           eventSource,
     188void WorkQueue::scheduleWorkOnSource(GSource* dispatchSource, PassOwnPtr<WorkItem> item, GSourceFunc sourceCallback)
     189{
     190    EventSource* eventSource = new EventSource(item, this, 0);
     191
     192    g_source_set_callback(dispatchSource, sourceCallback, eventSource,
    202193                          reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
    203194
     
    211202    g_source_set_priority(dispatchSource.get(), G_PRIORITY_DEFAULT);
    212203
    213     scheduleWorkOnSource(dispatchSource.get(), item);
     204    scheduleWorkOnSource(dispatchSource.get(), item, reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce));
    214205}
    215206
     
    219210    ASSERT(dispatchSource);
    220211
    221     scheduleWorkOnSource(dispatchSource.get(), item);
     212    scheduleWorkOnSource(dispatchSource.get(), item, reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce));
    222213}
    223214
     
    227218    ASSERT(dispatchSource);
    228219
    229     EventSource* eventSource = new EventSource(dispatchSource.get(), item, this, 0);
    230 
    231     g_source_set_callback(dispatchSource.get(),
    232                           reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnTermination),
    233                           eventSource,
    234                           reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
    235 
    236     g_source_attach(dispatchSource.get(), m_eventContext);
    237 }
     220    scheduleWorkOnSource(dispatchSource.get(), item, reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnTermination));
     221}
Note: See TracChangeset for help on using the changeset viewer.