Changeset 40888 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Feb 11, 2009, 11:58:36 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/MainThread.cpp
r40684 r40888 30 30 #include "MainThread.h" 31 31 32 #include "CurrentTime.h" 33 #include "Deque.h" 32 34 #include "StdLibExtras.h" 33 35 #include "Threading.h" 34 #include "Vector.h"35 36 36 37 namespace WTF { … … 49 50 }; 50 51 51 typedef Vector<FunctionWithContext> FunctionQueue;52 typedef Deque<FunctionWithContext> FunctionQueue; 52 53 53 54 static bool callbacksPaused; // This global variable is only accessed from main thread. … … 65 66 } 66 67 67 #if !PLATFORM(WIN) && !PLATFORM(CHROMIUM)68 68 void initializeMainThread() 69 69 { 70 70 mainThreadFunctionQueueMutex(); 71 initializeMainThreadPlatform(); 71 72 } 72 #endif 73 74 // 0.1 sec delays in UI is approximate threshold when they become noticeable. Have a limit that's half of that. 75 static const double maxRunLoopSuspensionTime = 0.05; 73 76 74 77 void dispatchFunctionsFromMainThread() … … 79 82 return; 80 83 81 FunctionQueue queueCopy; 82 { 83 MutexLocker locker(mainThreadFunctionQueueMutex()); 84 queueCopy.swap(functionQueue()); 85 } 84 double startTime = currentTime(); 86 85 87 for (unsigned i = 0; i < queueCopy.size(); ++i) { 88 FunctionWithContext& invocation = queueCopy[i]; 86 FunctionWithContext invocation; 87 while (true) { 88 { 89 MutexLocker locker(mainThreadFunctionQueueMutex()); 90 if (!functionQueue().size()) 91 break; 92 invocation = functionQueue().first(); 93 functionQueue().removeFirst(); 94 } 95 89 96 invocation.function(invocation.context); 90 97 if (invocation.syncFlag) 91 98 invocation.syncFlag->signal(); 99 100 // If we are running accumulated functions for too long so UI may become unresponsive, we need to 101 // yield so the user input can be processed. Otherwise user may not be able to even close the window. 102 // This code has effect only in case the scheduleDispatchFunctionsOnMainThread() is implemented in a way that 103 // allows input events to be processed before we are back here. 104 if (currentTime() - startTime > maxRunLoopSuspensionTime) { 105 scheduleDispatchFunctionsOnMainThread(); 106 break; 107 } 92 108 } 93 109 } … … 96 112 { 97 113 ASSERT(function); 98 114 bool needToSchedule = false; 99 115 { 100 116 MutexLocker locker(mainThreadFunctionQueueMutex()); 117 needToSchedule = functionQueue().size() == 0; 101 118 functionQueue().append(FunctionWithContext(function, context)); 102 119 } 103 104 scheduleDispatchFunctionsOnMainThread();120 if (needToSchedule) 121 scheduleDispatchFunctionsOnMainThread(); 105 122 } 106 123 … … 116 133 ThreadCondition syncFlag; 117 134 Mutex conditionMutex; 118 135 bool needToSchedule = false; 119 136 { 120 137 MutexLocker locker(mainThreadFunctionQueueMutex()); 138 needToSchedule = functionQueue().size() == 0; 121 139 functionQueue().append(FunctionWithContext(function, context, &syncFlag)); 122 140 conditionMutex.lock(); 123 141 } 124 142 125 scheduleDispatchFunctionsOnMainThread(); 143 if (needToSchedule) 144 scheduleDispatchFunctionsOnMainThread(); 126 145 syncFlag.wait(conditionMutex); 127 146 } -
trunk/JavaScriptCore/wtf/MainThread.h
r36056 r40888 46 46 47 47 // These functions are internal to the callOnMainThread implementation. 48 void dispatchFunctionsFromMainThread();48 void initializeMainThreadPlatform(); 49 49 void scheduleDispatchFunctionsOnMainThread(); 50 50 Mutex& mainThreadFunctionQueueMutex(); 51 void dispatchFunctionsFromMainThread(); 51 52 52 53 } // namespace WTF -
trunk/JavaScriptCore/wtf/chromium/MainThreadChromium.cpp
r40684 r40888 36 36 namespace WTF { 37 37 38 void initializeMainThread ()38 void initializeMainThreadPlatform() 39 39 { 40 40 ChromiumThreading::initializeMainThread(); -
trunk/JavaScriptCore/wtf/gtk/MainThreadGtk.cpp
r31730 r40888 35 35 namespace WTF { 36 36 37 void initializeMainThreadPlatform() 38 { 39 } 40 37 41 static gboolean timeoutFired(gpointer) 38 42 { … … 46 50 } 47 51 48 49 } 52 } // namespace WTF -
trunk/JavaScriptCore/wtf/mac/MainThreadMac.mm
r31730 r40888 31 31 32 32 #import <Foundation/NSThread.h> 33 #import <wtf/Assertions.h> 33 34 34 35 @interface WTFMainThreadCaller : NSObject { … … 48 49 namespace WTF { 49 50 51 static WTFMainThreadCaller* staticMainThreadCaller = nil; 52 53 void initializeMainThreadPlatform() 54 { 55 ASSERT(!staticMainThreadCaller); 56 staticMainThreadCaller = [[WTFMainThreadCaller alloc] init]; 57 } 58 50 59 void scheduleDispatchFunctionsOnMainThread() 51 60 { 52 WTFMainThreadCaller *caller = [[WTFMainThreadCaller alloc] init]; 53 [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO]; 54 [caller release]; 61 ASSERT(staticMainThreadCaller); 62 [staticMainThreadCaller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO]; 55 63 } 56 64 -
trunk/JavaScriptCore/wtf/qt/MainThreadQt.cpp
r37061 r40888 59 59 Q_GLOBAL_STATIC(MainThreadInvoker, webkit_main_thread_invoker) 60 60 61 void initializeMainThreadPlatform() 62 { 63 } 61 64 62 65 void scheduleDispatchFunctionsOnMainThread() … … 65 68 } 66 69 67 } 70 } // namespace WTF 68 71 69 72 #include "MainThreadQt.moc" -
trunk/JavaScriptCore/wtf/win/MainThreadWin.cpp
r38699 r40888 51 51 } 52 52 53 void initializeMainThread ()53 void initializeMainThreadPlatform() 54 54 { 55 55 if (threadingWindowHandle) 56 56 return; 57 58 mainThreadFunctionQueueMutex();59 57 60 58 WNDCLASSEX wcex; … … 76 74 } 77 75 78 } // namespace W ebCore76 } // namespace WTF -
trunk/JavaScriptCore/wtf/wx/MainThreadWx.cpp
r31730 r40888 32 32 namespace WTF { 33 33 34 void initializeMainThreadPlatform() 35 { 36 } 37 34 38 void scheduleDispatchFunctionsOnMainThread() 35 39 { 36 40 } 37 41 38 } 42 } // namespace WTF
Note:
See TracChangeset
for help on using the changeset viewer.