Changeset 162276 in webkit
- Timestamp:
- Jan 18, 2014 3:00:21 PM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r162275 r162276 1 2014-01-18 Anders Carlsson <andersca@apple.com> 2 3 Replace a couple of uses of WTF::Function with std::function 4 https://bugs.webkit.org/show_bug.cgi?id=127218 5 6 Reviewed by Andreas Kling. 7 8 * WebCore.exp.in: 9 * page/scrolling/ScrollingThread.cpp: 10 (WebCore::ScrollingThread::dispatch): 11 (WebCore::ScrollingThread::dispatchBarrier): 12 (WebCore::ScrollingThread::shared): 13 (WebCore::ScrollingThread::createThreadIfNeeded): 14 (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread): 15 * page/scrolling/ScrollingThread.h: 16 * page/scrolling/mac/ScrollingThreadMac.mm: 17 (WebCore::ScrollingThread::initializeRunLoop): 18 1 19 2014-01-18 Anders Carlsson <andersca@apple.com> 2 20 -
trunk/Source/WebCore/WebCore.exp.in
r162264 r162276 2979 2979 __ZN7WebCore13ScrollingTreeD1Ev 2980 2980 __ZN7WebCore13ScrollingTreeD2Ev 2981 __ZN7WebCore15ScrollingThread15dispatchBarrierE RKN3WTF8FunctionIFvvEEE2982 __ZN7WebCore15ScrollingThread8dispatchE RKN3WTF8FunctionIFvvEEE2981 __ZN7WebCore15ScrollingThread15dispatchBarrierENSt3__18functionIFvvEEE 2982 __ZN7WebCore15ScrollingThread8dispatchENSt3__18functionIFvvEEE 2983 2983 __ZN7WebCore18ScrollingStateNode8setLayerERKNS_19LayerRepresentationE 2984 2984 __ZN7WebCore18ScrollingStateTree10attachNodeENS_17ScrollingNodeTypeEyy -
trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp
r160944 r162276 30 30 31 31 #include <wtf/MainThread.h> 32 #include <wtf/NeverDestroyed.h> 32 33 33 34 namespace WebCore { … … 46 47 } 47 48 48 void ScrollingThread::dispatch( const Function<void()>&function)49 void ScrollingThread::dispatch(std::function<void ()> function) 49 50 { 50 51 shared().createThreadIfNeeded(); 51 52 52 53 { 53 MutexLocker locker(shared().m_functionsMutex);54 std::lock_guard<std::mutex> lock(shared().m_functionsMutex); 54 55 shared().m_functions.append(function); 55 56 } … … 58 59 } 59 60 60 static void callFunctionOnMainThread(const Function<void()>*function)61 void ScrollingThread::dispatchBarrier(std::function<void ()> function) 61 62 { 62 callOnMainThread(*function); 63 delete function; 64 } 65 66 void ScrollingThread::dispatchBarrier(const Function<void()>& function) 67 { 68 dispatch(bind(callFunctionOnMainThread, new Function<void()>(function))); 63 dispatch([function]{ 64 callOnMainThread(std::move(function)); 65 }); 69 66 } 70 67 71 68 ScrollingThread& ScrollingThread::shared() 72 69 { 73 DEFINE_STATIC_LOCAL(ScrollingThread, scrollingThread, ()); 70 static NeverDestroyed<ScrollingThread> scrollingThread; 71 74 72 return scrollingThread; 75 73 } … … 82 80 // Wait for the thread to initialize the run loop. 83 81 { 84 MutexLocker locker(m_initializeRunLoopConditionMutex);82 std::unique_lock<std::mutex> lock(m_initializeRunLoopMutex); 85 83 86 84 m_threadIdentifier = createThread(threadCallback, this, "WebCore: Scrolling"); 87 85 88 86 #if PLATFORM(MAC) 89 while (!m_threadRunLoop) 90 m_initializeRunLoopCondition.wait(m_initializeRunLoopConditionMutex); 87 m_initializeRunLoopConditionVariable.wait(lock, [this]{ return m_threadRunLoop; }); 91 88 #endif 92 89 } … … 107 104 ASSERT(isCurrentThread()); 108 105 109 Vector< Function<void()>> functions;106 Vector<std::function<void ()>> functions; 110 107 111 108 { 112 MutexLocker locker(m_functionsMutex);113 m_functions.swap(functions);109 std::lock_guard<std::mutex> lock(m_functionsMutex); 110 functions = std::move(m_functions); 114 111 } 115 116 for ( size_t i = 0; i < functions.size(); ++i)117 function s[i]();112 113 for (auto& function : functions) 114 function(); 118 115 } 119 116 -
trunk/Source/WebCore/page/scrolling/ScrollingThread.h
r160944 r162276 29 29 #if ENABLE(ASYNC_SCROLLING) 30 30 31 #include <wtf/Functional.h> 31 #include <condition_variable> 32 #include <functional> 33 #include <wtf/Forward.h> 32 34 #include <wtf/Noncopyable.h> 33 35 #include <wtf/Threading.h> … … 45 47 public: 46 48 static bool isCurrentThread(); 47 static void dispatch( const Function<void()>&);49 static void dispatch(std::function<void ()>); 48 50 49 51 // Will dispatch the given function on the main thread once all pending functions 50 52 // on the scrolling thread have finished executing. Used for synchronization purposes. 51 static void dispatchBarrier( const Function<void()>&);53 static void dispatchBarrier(std::function<void ()>); 52 54 53 55 private: 56 friend NeverDestroyed<ScrollingThread>; 57 54 58 ScrollingThread(); 55 59 … … 71 75 ThreadIdentifier m_threadIdentifier; 72 76 73 ThreadCondition m_initializeRunLoopCondition;74 Mutex m_initializeRunLoopConditionMutex;77 std::condition_variable m_initializeRunLoopConditionVariable; 78 std::mutex m_initializeRunLoopMutex; 75 79 76 Mutex m_functionsMutex;77 Vector< Function<void()>> m_functions;80 std::mutex m_functionsMutex; 81 Vector<std::function<void ()>> m_functions; 78 82 79 83 #if PLATFORM(MAC) -
trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm
r160944 r162276 35 35 // Initialize the run loop. 36 36 { 37 MutexLocker locker(m_initializeRunLoopConditionMutex);37 std::lock_guard<std::mutex> lock(m_initializeRunLoopMutex); 38 38 39 39 m_threadRunLoop = CFRunLoopGetCurrent(); … … 43 43 CFRunLoopAddSource(CFRunLoopGetCurrent(), m_threadRunLoopSource.get(), kCFRunLoopDefaultMode); 44 44 45 m_initializeRunLoopCondition .broadcast();45 m_initializeRunLoopConditionVariable.notify_all(); 46 46 } 47 47 -
trunk/Source/WebKit2/ChangeLog
r162271 r162276 1 2014-01-18 Anders Carlsson <andersca@apple.com> 2 3 Replace a couple of uses of WTF::Function with std::function 4 https://bugs.webkit.org/show_bug.cgi?id=127218 5 6 Reviewed by Andreas Kling. 7 8 * Platform/IPC/mac/ConnectionMac.cpp: 9 (IPC::createDataAvailableSource): 10 * Platform/WorkQueue.h: 11 * Platform/mac/WorkQueueMac.cpp: 12 (WorkQueue::dispatch): 13 (WorkQueue::dispatchAfter): 14 * Shared/ChildProcess.cpp: 15 (WebKit::didCloseOnConnectionWorkQueue): 16 * UIProcess/Storage/LocalStorageDatabase.cpp: 17 (WebKit::LocalStorageDatabase::scheduleDatabaseUpdate): 18 * WebProcess/WebPage/DrawingArea.cpp: 19 (WebKit::DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition): 20 * WebProcess/WebPage/DrawingArea.h: 21 * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h: 22 * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm: 23 (WebKit::TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition): 24 1 25 2014-01-18 Martin Hock <mhock@apple.com> 2 26 -
trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp
r161148 r162276 102 102 } 103 103 104 static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, WorkQueue* workQueue, const Function<void()>&function)104 static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, WorkQueue* workQueue, std::function<void ()> function) 105 105 { 106 106 dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, receivePort, 0, workQueue->dispatchQueue()); 107 dispatch_source_set_event_handler(source, function); 107 dispatch_source_set_event_handler(source, ^{ 108 function(); 109 }); 110 108 111 dispatch_source_set_cancel_handler(source, ^{ 109 112 mach_port_mod_refs(mach_task_self(), receivePort, MACH_PORT_RIGHT_RECEIVE, -1); -
trunk/Source/WebKit2/Platform/WorkQueue.h
r160162 r162276 32 32 #endif 33 33 34 #include <chrono> 35 #include <functional> 34 36 #include <wtf/Forward.h> 35 37 #include <wtf/Functional.h> … … 56 58 ~WorkQueue(); 57 59 58 // Will dispatch the given function to run as soon as possible. 59 void dispatch(const Function<void()>&); 60 61 // Will dispatch the given function after the given delay (in seconds). 62 void dispatchAfterDelay(const Function<void()>&, double delay); 60 void dispatch(std::function<void ()>); 61 void dispatchAfter(std::chrono::nanoseconds, std::function<void ()>); 63 62 64 63 #if OS(DARWIN) -
trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp
r141497 r162276 27 27 #include "WorkQueue.h" 28 28 29 void WorkQueue::dispatch( const Function<void()>&function)29 void WorkQueue::dispatch(std::function<void ()> function) 30 30 { 31 Function<void()> functionCopy = function;32 33 31 ref(); 34 32 dispatch_async(m_dispatchQueue, ^{ 35 function Copy();33 function(); 36 34 deref(); 37 35 }); 38 36 } 39 37 40 void WorkQueue::dispatchAfter Delay(const Function<void()>& function, double delay)38 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<void ()> function) 41 39 { 42 dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);43 44 Function<void()> functionCopy = function;45 46 40 ref(); 47 dispatch_after(d elayTime, m_dispatchQueue, ^{48 function Copy();41 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, ^{ 42 function(); 49 43 deref(); 50 44 }); -
trunk/Source/WebKit2/Shared/ChildProcess.cpp
r161271 r162276 45 45 } 46 46 47 NO_RETURN static void watchdogCallback()48 {49 // We use _exit here since the watchdog callback is called from another thread and we don't want50 // global destructors or atexit handlers to be called from this thread while the main thread is busy51 // doing its thing.52 _exit(EXIT_FAILURE);53 }54 55 47 static void didCloseOnConnectionWorkQueue(IPC::Connection*) 56 48 { 57 49 // If the connection has been closed and we haven't responded in the main thread for 10 seconds 58 50 // the process will exit forcibly. 59 const double watchdogDelay = 10;51 auto watchdogDelay = std::chrono::seconds(10); 60 52 61 WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfterDelay(bind(static_cast<void(*)()>(watchdogCallback)), watchdogDelay); 53 WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfter(watchdogDelay, []{ 54 // We use _exit here since the watchdog callback is called from another thread and we don't want 55 // global destructors or atexit handlers to be called from this thread while the main thread is busy 56 // doing its thing. 57 _exit(EXIT_FAILURE); 58 }); 62 59 } 63 60 -
trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp
r150304 r162276 40 40 using namespace WebCore; 41 41 42 static const double databaseUpdateIntervalInSeconds = 1.0;42 static const auto databaseUpdateInterval = std::chrono::seconds(1); 43 43 44 44 static const int maximumItemsToUpdate = 100; … … 242 242 243 243 m_didScheduleDatabaseUpdate = true; 244 m_queue->dispatchAfter Delay(bind(&LocalStorageDatabase::updateDatabase, this), databaseUpdateIntervalInSeconds);244 m_queue->dispatchAfter(databaseUpdateInterval, bind(&LocalStorageDatabase::updateDatabase, this)); 245 245 } 246 246 -
trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.cpp
r160031 r162276 78 78 } 79 79 80 void DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition( const Function<void ()>&function)80 void DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()> function) 81 81 { 82 82 // Scroll position updates are synchronous by default so we can just call the function right away here. -
trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.h
r161548 r162276 32 32 #include <WebCore/IntRect.h> 33 33 #include <WebCore/ViewState.h> 34 #include <functional> 34 35 #include <wtf/Forward.h> 35 36 #include <wtf/Noncopyable.h> … … 109 110 #endif 110 111 111 virtual void dispatchAfterEnsuringUpdatedScrollPosition( const Function<void ()>&);112 virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>); 112 113 113 114 virtual void viewStateDidChange(WebCore::ViewState::Flags) { } -
trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h
r162139 r162276 85 85 virtual void didChangeScrollOffsetForAnyFrame() override; 86 86 87 virtual void dispatchAfterEnsuringUpdatedScrollPosition( const Function<void()>&) override;87 virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>) override; 88 88 89 89 virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) override; -
trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm
r161530 r162276 301 301 } 302 302 303 void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>& functionRef) 304 { 305 Function<void ()> function = functionRef; 306 303 void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()> function) 304 { 307 305 #if ENABLE(ASYNC_SCROLLING) 308 306 if (!m_webPage->corePage()->scrollingCoordinator()) {
Note: See TracChangeset
for help on using the changeset viewer.