Changeset 83278 in webkit
- Timestamp:
- Apr 8, 2011 3:17:00 AM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r83277 r83278 1 2011-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 1 27 2011-04-08 Carlos Garcia Campos <cgarcia@igalia.com> 2 28 -
trunk/Source/WebKit2/Platform/WorkQueue.h
r81567 r83278 166 166 static void* startWorkQueueThread(WorkQueue*); 167 167 void workQueueThreadBody(); 168 void scheduleWorkOnSource(GSource*, PassOwnPtr<WorkItem>); 168 169 169 170 ThreadIdentifier m_workQueueThread; -
trunk/Source/WebKit2/Platform/gtk/WorkQueueGtk.cpp
r79335 r83278 30 30 #include "WKBase.h" 31 31 #include <WebCore/NotImplemented.h> 32 #include <gio/gio.h> 32 33 #include <glib.h> 34 #include <wtf/gobject/GRefPtr.h> 33 35 34 36 // WorkQueue::EventSource … … 44 46 GSource* dispatchSource() { return m_dispatchSource; } 45 47 46 static gboolean performWorkOnce(EventSource* eventSource)48 static gboolean executeEventSource(EventSource* eventSource) 47 49 { 48 50 ASSERT(eventSource); … … 55 57 56 58 eventSource->m_workItem->execute(); 59 60 return TRUE; 61 } 62 63 static gboolean performWorkOnce(EventSource* eventSource) 64 { 65 executeEventSource(eventSource); 57 66 return FALSE; 58 67 } 59 68 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 { 64 71 if (!(condition & G_IO_IN) && !(condition & G_IO_HUP) && !(condition & G_IO_ERR)) 65 72 return FALSE; 66 73 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; 75 77 76 78 if ((condition & G_IO_HUP) || (condition & G_IO_ERR)) … … 79 81 return TRUE; 80 82 } 81 83 82 84 static void deleteEventSource(EventSource* eventSource) 83 85 { … … 133 135 void WorkQueue::registerEventSourceHandler(int fileDescriptor, int condition, PassOwnPtr<WorkItem> item) 134 136 { 135 G IOChannel* 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); 138 140 ASSERT(dispatchSource); 139 141 EventSource* eventSource = new EventSource(dispatchSource, item, this); … … 155 157 } 156 158 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); 162 160 } 163 161 … … 181 179 } 182 180 181 void 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 183 193 void WorkQueue::scheduleWork(PassOwnPtr<WorkItem> item) 184 194 { 185 G Source* dispatchSource = g_timeout_source_new(0);195 GRefPtr<GSource> dispatchSource = adoptGRef(g_idle_source_new()); 186 196 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 202 void 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.