Changeset 83278 in webkit


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

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

Reviewed by Martin Robinson.

[GTK] Implement scheduleWorkAfterDelay() in WorkQueueGtk
https://bugs.webkit.org/show_bug.cgi?id=57434

  • Platform/WorkQueue.h:
  • Platform/gtk/WorkQueueGtk.cpp: (WorkQueue::EventSource::executeEventSource): This new method contains the common code to execute a work item. (WorkQueue::EventSource::performWorkOnce): Use executeEventSource() to execute the work item. (WorkQueue::EventSource::performWork): Use executeEventSource() to execute the work item. (WorkQueue::registerEventSourceHandler): Use a GSocket instead of a GIOChannel since the API is newer and allows us to pass a cancellable object to be able to cancel the source. (WorkQueue::scheduleWorkOnSource): This new method contains the common code to attach a source to a context. It doesn't use a lock anymore, since g_source_attach() uses its own mutex internally. (WorkQueue::scheduleWork): Use an idle source instead of a timeout one, changing the priority to G_PRIORITY_DEFAULT. (WorkQueue::scheduleWorkAfterDelay): Implement it using a timeout source with the given delay.
Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r83277 r83278  
     12011-04-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Implement scheduleWorkAfterDelay() in WorkQueueGtk
     6        https://bugs.webkit.org/show_bug.cgi?id=57434
     7
     8        * Platform/WorkQueue.h:
     9        * Platform/gtk/WorkQueueGtk.cpp:
     10        (WorkQueue::EventSource::executeEventSource): This new method
     11        contains the common code to execute a work item.
     12        (WorkQueue::EventSource::performWorkOnce): Use
     13        executeEventSource() to execute the work item.
     14        (WorkQueue::EventSource::performWork): Use executeEventSource() to
     15        execute the work item.
     16        (WorkQueue::registerEventSourceHandler): Use a GSocket instead of
     17        a GIOChannel since the API is newer and allows us to pass a
     18        cancellable object to be able to cancel the source.
     19        (WorkQueue::scheduleWorkOnSource): This new method contains the
     20        common code to attach a source to a context. It doesn't use a lock
     21        anymore, since g_source_attach() uses its own mutex internally.
     22        (WorkQueue::scheduleWork): Use an idle source instead of a timeout
     23        one, changing the priority to G_PRIORITY_DEFAULT.
     24        (WorkQueue::scheduleWorkAfterDelay): Implement it using a timeout
     25        source with the given delay.
     26
    1272011-04-08  Carlos Garcia Campos  <cgarcia@igalia.com>
    228
  • trunk/Source/WebKit2/Platform/WorkQueue.h

    r81567 r83278  
    166166    static void* startWorkQueueThread(WorkQueue*);
    167167    void workQueueThreadBody();
     168    void scheduleWorkOnSource(GSource*, PassOwnPtr<WorkItem>);
    168169
    169170    ThreadIdentifier m_workQueueThread;
  • trunk/Source/WebKit2/Platform/gtk/WorkQueueGtk.cpp

    r79335 r83278  
    3030#include "WKBase.h"
    3131#include <WebCore/NotImplemented.h>
     32#include <gio/gio.h>
    3233#include <glib.h>
     34#include <wtf/gobject/GRefPtr.h>
    3335
    3436// WorkQueue::EventSource
     
    4446    GSource* dispatchSource() { return m_dispatchSource; }
    4547
    46     static gboolean performWorkOnce(EventSource* eventSource)
     48    static gboolean executeEventSource(EventSource* eventSource)
    4749    {
    4850        ASSERT(eventSource);
     
    5557
    5658        eventSource->m_workItem->execute();
     59
     60        return TRUE;
     61    }
     62
     63    static gboolean performWorkOnce(EventSource* eventSource)
     64    {
     65        executeEventSource(eventSource);
    5766        return FALSE;
    5867    }
    5968
    60     static gboolean performWork(GIOChannel* channel, GIOCondition condition, EventSource* eventSource)
    61     {
    62         ASSERT(eventSource);
    63 
     69    static gboolean performWork(GSocket* socket, GIOCondition condition, EventSource* eventSource)
     70    {
    6471        if (!(condition & G_IO_IN) && !(condition & G_IO_HUP) && !(condition & G_IO_ERR))
    6572            return FALSE;
    6673
    67         WorkQueue* queue = eventSource->m_workQueue;
    68         {
    69             MutexLocker locker(queue->m_isValidMutex);
    70             if (!queue->m_isValid)
    71                 return FALSE;
    72         }
    73 
    74         eventSource->m_workItem->execute();
     74
     75        if (!executeEventSource(eventSource))
     76            return FALSE;
    7577
    7678        if ((condition & G_IO_HUP) || (condition & G_IO_ERR))
     
    7981        return TRUE;
    8082    }
    81    
     83
    8284    static void deleteEventSource(EventSource* eventSource)
    8385    {
     
    133135void WorkQueue::registerEventSourceHandler(int fileDescriptor, int condition, PassOwnPtr<WorkItem> item)
    134136{
    135     GIOChannel* channel = g_io_channel_unix_new(fileDescriptor);
    136     ASSERT(channel);
    137     GSource* dispatchSource = g_io_create_watch(channel, static_cast<GIOCondition>(condition));
     137    GRefPtr<GSocket> socket = adoptGRef(g_socket_new_from_fd(fileDescriptor, 0));
     138    ASSERT(socket);
     139    GSource* dispatchSource = g_socket_create_source(socket.get(), static_cast<GIOCondition>(condition), 0);
    138140    ASSERT(dispatchSource);
    139141    EventSource* eventSource = new EventSource(dispatchSource, item, this);
     
    155157    }
    156158
    157     // Attach the event source to the GMainContext under the mutex since this is shared across multiple threads.
    158     {
    159         MutexLocker locker(m_eventLoopLock);
    160         g_source_attach(dispatchSource, m_eventContext);
    161     }
     159    g_source_attach(dispatchSource, m_eventContext);
    162160}
    163161
     
    181179}
    182180
     181void WorkQueue::scheduleWorkOnSource(GSource* dispatchSource, PassOwnPtr<WorkItem> item)
     182{
     183    EventSource* eventSource = new EventSource(dispatchSource, item, this);
     184
     185    g_source_set_callback(dispatchSource,
     186                          reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce),
     187                          eventSource,
     188                          reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
     189
     190    g_source_attach(dispatchSource, m_eventContext);
     191}
     192
    183193void WorkQueue::scheduleWork(PassOwnPtr<WorkItem> item)
    184194{
    185     GSource* dispatchSource = g_timeout_source_new(0);
     195    GRefPtr<GSource> dispatchSource = adoptGRef(g_idle_source_new());
    186196    ASSERT(dispatchSource);
    187     EventSource* eventSource = new EventSource(dispatchSource, item, this);
    188    
    189     g_source_set_callback(dispatchSource,
    190                           reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce),
    191                           eventSource,
    192                           reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
    193     {
    194         MutexLocker locker(m_eventLoopLock);
    195         g_source_attach(dispatchSource, m_eventContext);
    196     }
    197 }
    198 
    199 void WorkQueue::scheduleWorkAfterDelay(PassOwnPtr<WorkItem>, double)
    200 {
    201     notImplemented();
    202 }
     197    g_source_set_priority(dispatchSource.get(), G_PRIORITY_DEFAULT);
     198
     199    scheduleWorkOnSource(dispatchSource.get(), item);
     200}
     201
     202void WorkQueue::scheduleWorkAfterDelay(PassOwnPtr<WorkItem> item, double delay)
     203{
     204    GRefPtr<GSource> dispatchSource = adoptGRef(g_timeout_source_new(static_cast<guint>(delay * 1000)));
     205    ASSERT(dispatchSource);
     206
     207    scheduleWorkOnSource(dispatchSource.get(), item);
     208}
Note: See TracChangeset for help on using the changeset viewer.