Changeset 31063 in webkit
- Timestamp:
- Mar 14, 2008 12:53:37 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 12 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r31060 r31063 1 2008-03-13 Adam Roben <aroben@apple.com> 2 3 Make most of callOnMainThread's implementation be cross-platform 4 5 I took the non-platform-specific parts of MainThreadWin.cpp and moved 6 them to a new MainThread.cpp. Each platform is now responsible for 7 implementing one function, scheduleDispatchFunctionsOnMainThread, 8 which is supposed to set things up so that 9 dispatchFunctionsFromMainThread gets called from the main thread in 10 the near future. 11 12 Reviewed by Alexey. 13 14 * GNUmakefile.am: Added MainThread.cpp to the project. 15 * WebCore.pro: Ditto. 16 * WebCore.vcproj/WebCore.vcproj: Ditto. 17 * WebCore.xcodeproj/project.pbxproj: Ditto. 18 * WebCoreSources.bkl: Ditto. 19 * platform/MainThread.cpp: 20 - Copied from WebCore/platform/win/MainThreadWin.cpp. 21 - Removed the Windows-specific parts. 22 (WebCore::callOnMainThread): Changed to call 23 scheduleDispatchFunctionsOnMainThread instead of PostMessage. 24 * platform/gtk/MainThreadGtk.cpp: 25 (WebCore::timeoutFired): Renamed from callFunctionOnMainThread. Now 26 just calls dispatchFunctionsFromMainThread. 27 (WebCore::scheduleDispatchFunctionsOnMainThread): Added. Calls through 28 to g_timeout_add. 29 * platform/mac/MainThreadMac.mm: Renamed WebCoreFunctionWrapper to 30 WebCoreMainThreadCaller. 31 (-[WebCoreMainThreadCaller call]): Calls through to 32 dispatchFunctionsFromMainThread. 33 (WebCore::scheduleDispatchFunctionsOnMainThread): Makes a new 34 WebCoreMainThreadCaller and calls performSelectorOnMainThread on it. 35 * platform/qt/MainThreadQt.cpp: Removed PerformFunctionEvent. 36 (WebCore::MainThreadInvoker::event): Chagned to call through to 37 dispatchFunctionsFromMainThread. 38 (WebCore::scheduleDispatchFunctionsOnMainThread): Sends an empty event 39 to the MainThreadInvoker. 40 * platform/win/MainThreadWin.cpp: 41 - Removed the non-Windows-specific parts. 42 - Removed some unnecessary initialization of static variables to 0. 43 (WebCore::ThreadingWindowWndProc): Changed to call 44 dispatchFunctionsFromMainThread. 45 (WebCore::scheduleDispatchFunctionsOnMainThread): Calls through to 46 PostMessage. 47 * platform/wx/MainThreadWx.cpp: 48 (WebCore::scheduleDispatchFunctionsOnMainThread): Added. 49 1 50 2008-03-14 Beth Dakin <bdakin@apple.com> 2 51 -
trunk/WebCore/GNUmakefile.am
r30989 r31063 856 856 WebCore/platform/Logging.cpp \ 857 857 WebCore/platform/MIMETypeRegistry.cpp \ 858 WebCore/platform/MainThread.cpp \ 858 859 WebCore/platform/network/AuthenticationChallengeBase.cpp \ 859 860 WebCore/platform/network/Credential.cpp \ -
trunk/WebCore/WebCore.pro
r30960 r31063 793 793 platform/Logging.cpp \ 794 794 platform/MIMETypeRegistry.cpp \ 795 platform/MainThread.cpp \ 795 796 platform/network/AuthenticationChallengeBase.cpp \ 796 797 platform/network/Credential.cpp \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r31033 r31063 3661 3661 </File> 3662 3662 <File 3663 RelativePath="..\platform\MainThread.cpp" 3664 > 3665 </File> 3666 <File 3663 3667 RelativePath="..\platform\MainThread.h" 3664 3668 > -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r31051 r31063 333 333 1CB4214D0AF2B2CA0085AD91 /* DOMRangeInternal.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 8538F05A0AD722F1006A81D1 /* DOMRangeInternal.h */; }; 334 334 1CE24F970D7CAF0E007E04C2 /* SchedulePairMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CE24F960D7CAF0E007E04C2 /* SchedulePairMac.mm */; }; 335 1CE3F8B40D89CFDC00FB035F /* MainThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CE3F8B30D89CFDC00FB035F /* MainThread.cpp */; }; 335 336 1CE83AC30ADAFFD7009354F6 /* DeleteButtonController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C4C8EFF0AD85D87009475CE /* DeleteButtonController.cpp */; }; 336 337 1CE83AC40ADAFFD8009354F6 /* DeleteButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C4C8F630AD8655D009475CE /* DeleteButton.cpp */; }; … … 4675 4676 1CDD45E60BA9C84600F90147 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; }; 4676 4677 1CE24F960D7CAF0E007E04C2 /* SchedulePairMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SchedulePairMac.mm; sourceTree = "<group>"; }; 4678 1CE3F8B30D89CFDC00FB035F /* MainThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MainThread.cpp; path = mac/MainThread.cpp; sourceTree = "<group>"; }; 4677 4679 1CEFC9B70D78DC8C007D2579 /* SchedulePair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SchedulePair.h; sourceTree = "<group>"; }; 4678 4680 1CEFC9B80D78DC8C007D2579 /* SchedulePair.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SchedulePair.cpp; sourceTree = "<group>"; }; … … 12009 12011 A8239DFE09B3CF8A00B60641 /* Logging.cpp */, 12010 12012 A8239DFF09B3CF8A00B60641 /* Logging.h */, 12013 1CE3F8B30D89CFDC00FB035F /* MainThread.cpp */, 12011 12014 E1EE79360D6C97DE00FEA3BA /* MainThread.h */, 12012 12015 BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */, … … 16179 16182 A9D248060D757E7D00FDF959 /* JSMimeType.cpp in Sources */, 16180 16183 A9D248080D757E7D00FDF959 /* JSMimeTypeArray.cpp in Sources */, 16184 1CE3F8B40D89CFDC00FB035F /* MainThread.cpp in Sources */, 16181 16185 ); 16182 16186 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/WebCoreSources.bkl
r30924 r31063 611 611 platform/Logging.cpp 612 612 platform/MIMETypeRegistry.cpp 613 platform/MainThread.cpp 613 614 platform/text/RegularExpression.cpp 614 615 platform/ScrollBar.cpp -
trunk/WebCore/platform/MainThread.cpp
r31062 r31063 1 1 /* 2 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)4 3 * 5 4 * Redistribution and use in source and binary forms, with or without … … 12 11 * notice, this list of conditions and the following disclaimer in the 13 12 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Inc. ("Apple") nor the names of13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 14 * its contributors may be used to endorse or promote products derived 16 15 * from this software without specific prior written permission. … … 31 30 #include "MainThread.h" 32 31 33 #include <glib.h> 32 #include "Logging.h" 33 #include <wtf/Vector.h> 34 34 35 35 namespace WebCore { … … 38 38 MainThreadFunction* function; 39 39 void* context; 40 FunctionWithContext(MainThreadFunction* f = 0, void* c = 0) : function(f), context(c) { } 40 41 }; 41 42 42 static gboolean callFunctionOnMainThread(gpointer data) 43 typedef Vector<FunctionWithContext> FunctionQueue; 44 45 static Mutex& functionQueueMutex() 43 46 { 44 FunctionWithContext* functionWithContext = static_cast<FunctionWithContext*>(data); 45 functionWithContext->function(functionWithContext->context); 46 delete functionWithContext; 47 return FALSE; 47 static Mutex staticFunctionQueueMutex; 48 return staticFunctionQueueMutex; 49 } 50 51 static FunctionQueue& functionQueue() 52 { 53 static FunctionQueue staticFunctionQueue; 54 return staticFunctionQueue; 55 } 56 57 void dispatchFunctionsFromMainThread() 58 { 59 FunctionQueue queueCopy; 60 { 61 MutexLocker locker(functionQueueMutex()); 62 queueCopy.swap(functionQueue()); 63 } 64 65 LOG(Threading, "Calling %u functions on the main thread", queueCopy.size()); 66 for (unsigned i = 0; i < queueCopy.size(); ++i) 67 queueCopy[i].function(queueCopy[i].context); 48 68 } 49 69 … … 51 71 { 52 72 ASSERT(function); 53 FunctionWithContext* functionWithContext = new FunctionWithContext; 54 functionWithContext->function = function; 55 functionWithContext->context = context; 56 g_timeout_add(0, callFunctionOnMainThread, functionWithContext); 73 74 { 75 MutexLocker locker(functionQueueMutex()); 76 functionQueue().append(FunctionWithContext(function, context)); 77 } 78 79 scheduleDispatchFunctionsOnMainThread(); 57 80 } 58 81 59 60 } 82 } // namespace WebCore -
trunk/WebCore/platform/MainThread.h
r30522 r31063 48 48 #endif 49 49 50 // These functions are internal to the callOnMainThread implementation. 51 void dispatchFunctionsFromMainThread(); 52 void scheduleDispatchFunctionsOnMainThread(); 50 53 51 54 } // namespace WebCore -
trunk/WebCore/platform/gtk/MainThreadGtk.cpp
r30522 r31063 35 35 namespace WebCore { 36 36 37 struct FunctionWithContext { 38 MainThreadFunction* function; 39 void* context; 40 }; 41 42 static gboolean callFunctionOnMainThread(gpointer data) 37 static gboolean timeoutFired(gpointer) 43 38 { 44 FunctionWithContext* functionWithContext = static_cast<FunctionWithContext*>(data); 45 functionWithContext->function(functionWithContext->context); 46 delete functionWithContext; 39 dispatchFunctionsFromMainThread(); 47 40 return FALSE; 48 41 } 49 42 50 void callOnMainThread(MainThreadFunction* function, void* context)43 void scheduleDispatchFunctionsOnMainThread() 51 44 { 52 ASSERT(function); 53 FunctionWithContext* functionWithContext = new FunctionWithContext; 54 functionWithContext->function = function; 55 functionWithContext->context = context; 56 g_timeout_add(0, callFunctionOnMainThread, functionWithContext); 45 g_timeout_add(0, timeoutFired, 0); 57 46 } 58 47 -
trunk/WebCore/platform/mac/MainThreadMac.mm
r30522 r31063 30 30 #import "MainThread.h" 31 31 32 @interface WebCoreFunctionWrapper : NSObject { 33 WebCore::MainThreadFunction* m_function; 34 void* m_context; 32 @interface WebCoreMainThreadCaller : NSObject { 35 33 } 36 - (id)initWithFunction:(WebCore::MainThreadFunction*)function context:(void*)context; 37 - (void)invoke; 34 - (void)call; 38 35 @end 39 36 40 @implementation WebCore FunctionWrapper37 @implementation WebCoreMainThreadCaller 41 38 42 - ( id)initWithFunction:(WebCore::MainThreadFunction*)function context:(void*)context;39 - (void)call 43 40 { 44 [super init]; 45 m_function = function; 46 m_context = context; 47 return self; 41 dispatchFunctionsFromMainThread(); 48 42 } 49 43 50 - (void)invoke 51 { 52 m_function(m_context); 53 } 54 55 @end // implementation WebCoreFunctionWrapper 44 @end // implementation WebCoreMainThreadCaller 56 45 57 46 namespace WebCore { 58 47 59 void callOnMainThread(MainThreadFunction* function, void* context)48 void scheduleDispatchFunctionsOnMainThread() 60 49 { 61 WebCore FunctionWrapper *wrapper = [[WebCoreFunctionWrapper alloc] initWithFunction:function context:context];62 [ wrapper performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:NO];63 [ wrapper release];50 WebCoreMainThreadCaller *caller = [[WebCoreMainThreadCaller alloc] init]; 51 [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO]; 52 [caller release]; 64 53 } 65 54 -
trunk/WebCore/platform/qt/MainThreadQt.cpp
r30522 r31063 38 38 namespace WebCore { 39 39 40 class PerformFunctionEvent : public QEvent {41 public:42 static const int EventType = 723;43 44 PerformFunctionEvent(MainThreadFunction*, void* context);45 46 void invoke();47 48 private:49 MainThreadFunction* m_function;50 void* m_context;51 };52 53 40 class MainThreadInvoker : public QObject { 54 41 Q_OBJECT … … 60 47 }; 61 48 62 PerformFunctionEvent::PerformFunctionEvent(MainThreadFunction* function, void* context)63 : QEvent(static_cast<QEvent::Type>(EventType))64 , m_function(function)65 , m_context(context)66 {67 }68 69 void PerformFunctionEvent::invoke()70 {71 m_function(m_context);72 }73 74 49 MainThreadInvoker::MainThreadInvoker() 75 50 { … … 77 52 } 78 53 79 bool MainThreadInvoker::event(QEvent* event)54 bool MainThreadInvoker::event(QEvent*) 80 55 { 81 if (event->type() == PerformFunctionEvent::EventType) 82 static_cast<PerformFunctionEvent*>(event)->invoke(); 83 84 return QObject::event(event); 56 dispatchFunctionsFromMainThread(); 85 57 } 86 58 … … 88 60 89 61 90 void callOnMainThread(MainThreadFunction* function, void* context)62 void scheduleDispatchFunctionsOnMainThread() 91 63 { 92 QCoreApplication::postEvent(webkit_main_thread_invoker(), new PerformFunctionEvent(function, context));64 QCoreApplication::postEvent(webkit_main_thread_invoker(), 0); 93 65 } 94 66 -
trunk/WebCore/platform/win/MainThreadWin.cpp
r30522 r31063 30 30 #include "MainThread.h" 31 31 32 #include "Logging.h"33 32 #include "Page.h" 34 33 #include <windows.h> … … 36 35 namespace WebCore { 37 36 38 struct FunctionWithContext { 39 MainThreadFunction* function; 40 void* context; 41 FunctionWithContext(MainThreadFunction* f = 0, void* c = 0) : function(f), context(c) { } 42 }; 43 44 typedef Vector<FunctionWithContext> FunctionQueue; 45 46 static HWND threadingWindowHandle = 0; 47 static UINT threadingFiredMessage = 0; 37 static HWND threadingWindowHandle; 38 static UINT threadingFiredMessage; 48 39 const LPCWSTR kThreadingWindowClassName = L"ThreadingWindowClass"; 49 static bool processingCustomThreadingMessage = false;50 51 static Mutex& functionQueueMutex()52 {53 static Mutex staticFunctionQueueMutex;54 return staticFunctionQueueMutex;55 }56 57 static FunctionQueue& functionQueue()58 {59 static FunctionQueue staticFunctionQueue;60 return staticFunctionQueue;61 }62 63 static void callFunctionsOnMainThread()64 {65 FunctionQueue queueCopy;66 {67 MutexLocker locker(functionQueueMutex());68 queueCopy.swap(functionQueue());69 }70 71 LOG(Threading, "Calling %u functions on the main thread", queueCopy.size());72 for (unsigned i = 0; i < queueCopy.size(); ++i)73 queueCopy[i].function(queueCopy[i].context);74 }75 40 76 41 LRESULT CALLBACK ThreadingWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 77 42 { 78 if (message == threadingFiredMessage) { 79 processingCustomThreadingMessage = true; 80 callFunctionsOnMainThread(); 81 processingCustomThreadingMessage = false; 82 } else 43 if (message == threadingFiredMessage) 44 dispatchFunctionsFromMainThread(); 45 else 83 46 return DefWindowProc(hWnd, message, wParam, lParam); 84 47 return 0; … … 104 67 threadingFiredMessage = RegisterWindowMessage(L"com.apple.WebKit.MainThreadFired"); 105 68 } 106 107 void callOnMainThread(MainThreadFunction* function, void* context)69 70 void scheduleDispatchFunctionsOnMainThread() 108 71 { 109 ASSERT(function);110 72 ASSERT(threadingWindowHandle); 111 112 if (processingCustomThreadingMessage)113 LOG(Threading, "callOnMainThread() called recursively. Beware of nested PostMessage()s");114 115 {116 MutexLocker locker(functionQueueMutex());117 functionQueue().append(FunctionWithContext(function, context));118 }119 120 73 PostMessage(threadingWindowHandle, threadingFiredMessage, 0, 0); 121 74 } -
trunk/WebCore/platform/wx/MainThreadWx.cpp
r30522 r31063 28 28 29 29 #include "config.h" 30 #include "MainThread.h" 31 30 32 #include "NotImplemented.h" 31 #include "MainThread.h"32 33 33 34 namespace WebCore { 34 35 35 void callOnMainThread(MainThreadFunction*, void*)36 void scheduleDispatchFunctionsOnMainThread() 36 37 { 37 38 notImplemented();
Note: See TracChangeset
for help on using the changeset viewer.