Changeset 261494 in webkit
- Timestamp:
- May 11, 2020 2:51:26 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r261493 r261494 1 2020-05-11 Simon Fraser <simon.fraser@apple.com> 2 3 Have ScrollingThread use a RunLoop rather than rolling its own 4 https://bugs.webkit.org/show_bug.cgi?id=211730 5 6 Reviewed by Darin Adler. 7 8 ScrollingThread rolled its own runloop/function dispatch by dropping to CF for macOS. 9 Fix to use RunLoop which provides the same functionality. 10 11 There was also a race creating the ScrollingThread for the first time, since both 12 the main thread, and EventDispatcher can call ScrollingThread::dispatch() early on, 13 so fix with a std::once block. 14 15 * SourcesCocoa.txt: 16 * WebCore.xcodeproj/project.pbxproj: 17 * page/scrolling/ScrollingThread.cpp: 18 (WebCore::ScrollingThread::singleton): 19 (WebCore::ScrollingThread::dispatch): 20 (WebCore::ScrollingThread::createThreadIfNeeded): 21 (WebCore::ScrollingThread::initializeRunLoop): 22 (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread): Deleted. 23 (WebCore::ScrollingThread::wakeUpRunLoop): Deleted. 24 (WebCore::ScrollingThread::threadRunLoopSourceCallback): Deleted. 25 * page/scrolling/ScrollingThread.h: 26 (WebCore::ScrollingThread::runLoop): 27 * page/scrolling/mac/ScrollingThreadMac.mm: Removed. 28 1 29 2020-05-11 Peng Liu <peng.liu6@apple.com> 2 30 -
trunk/Source/WebCore/SourcesCocoa.txt
r261442 r261494 160 160 page/scrolling/mac/ScrollingMomentumCalculatorMac.mm 161 161 page/scrolling/mac/ScrollingStateScrollingNodeMac.mm 162 page/scrolling/mac/ScrollingThreadMac.mm163 162 page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm 164 163 page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm -
trunk/Source/WebCore/SourcesGTK.txt
r260420 r261494 60 60 page/scrolling/nicosia/ScrollingTreePositionedNode.cpp 61 61 page/scrolling/nicosia/ScrollingTreeStickyNode.cpp 62 63 page/scrolling/generic/ScrollingThreadGeneric.cpp64 62 65 63 platform/ScrollAnimationKinetic.cpp -
trunk/Source/WebCore/SourcesWPE.txt
r257299 r261494 58 58 page/scrolling/nicosia/ScrollingTreeStickyNode.cpp 59 59 60 page/scrolling/generic/ScrollingThreadGeneric.cpp61 62 60 platform/ScrollAnimationKinetic.cpp 63 61 platform/UserAgentQuirks.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r261442 r261494 6504 6504 1AF62F2014DAFE790041556C /* ScrollingThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingThread.cpp; sourceTree = "<group>"; }; 6505 6505 1AF62F2114DAFE790041556C /* ScrollingThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingThread.h; sourceTree = "<group>"; }; 6506 1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingThreadMac.mm; sourceTree = "<group>"; };6507 6506 1AF7AFC51A48A8BC00C8E4E7 /* SecurityOriginPolicy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityOriginPolicy.cpp; sourceTree = "<group>"; }; 6508 6507 1AF7AFC61A48A8BC00C8E4E7 /* SecurityOriginPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecurityOriginPolicy.h; sourceTree = "<group>"; }; … … 17675 17674 517DEEE31DE94ADC00B91644 /* ScrollingMomentumCalculatorMac.mm */, 17676 17675 0F73B765222B327F00805316 /* ScrollingStateScrollingNodeMac.mm */, 17677 1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */,17678 17676 93C4A4131629DF5A00C3EB6E /* ScrollingTreeFrameScrollingNodeMac.h */, 17679 17677 93C4A4141629DF5A00C3EB6E /* ScrollingTreeFrameScrollingNodeMac.mm */, -
trunk/Source/WebCore/page/MemoryRelease.cpp
r260195 r261494 149 149 // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself. 150 150 WorkerThread::releaseFastMallocFreeMemoryInAllThreads(); 151 #if ENABLE( ASYNC_SCROLLING) && !PLATFORM(IOS_FAMILY)151 #if ENABLE(SCROLLING_THREAD) 152 152 ScrollingThread::dispatch(WTF::releaseFastMallocFreeMemory); 153 153 #endif -
trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp
r257688 r261494 27 27 #include "ScrollingThread.h" 28 28 29 #if ENABLE( ASYNC_SCROLLING)29 #if ENABLE(SCROLLING_THREAD) 30 30 31 31 #include <mutex> 32 32 #include <wtf/MainThread.h> 33 33 #include <wtf/NeverDestroyed.h> 34 #include <wtf/threads/BinarySemaphore.h> 34 35 35 36 namespace WebCore { 36 37 38 ScrollingThread& ScrollingThread::singleton() 39 { 40 static LazyNeverDestroyed<ScrollingThread> scrollingThread; 41 static std::once_flag onceFlag; 42 std::call_once(onceFlag, [] { 43 scrollingThread.construct(); 44 }); 45 46 return scrollingThread; 47 } 48 37 49 ScrollingThread::ScrollingThread() 38 50 { 51 BinarySemaphore semaphore; 52 m_thread = Thread::create("WebCore: Scrolling", [this, &semaphore] { 53 WTF::Thread::setCurrentThreadIsUserInteractive(); 54 m_runLoop = &RunLoop::current(); 55 semaphore.signal(); 56 m_runLoop->run(); 57 }); 58 59 semaphore.wait(); 39 60 } 40 61 … … 46 67 void ScrollingThread::dispatch(Function<void ()>&& function) 47 68 { 48 auto& scrollingThread = ScrollingThread::singleton(); 49 scrollingThread.createThreadIfNeeded(); 50 51 { 52 auto locker = holdLock(scrollingThread.m_functionsMutex); 53 scrollingThread.m_functions.append(WTFMove(function)); 54 } 55 56 scrollingThread.wakeUpRunLoop(); 69 ScrollingThread::singleton().runLoop().dispatch(WTFMove(function)); 57 70 } 58 71 … … 64 77 } 65 78 66 ScrollingThread& ScrollingThread::singleton()67 {68 static NeverDestroyed<ScrollingThread> scrollingThread;69 70 return scrollingThread;71 }72 73 void ScrollingThread::createThreadIfNeeded()74 {75 // Wait for the thread to initialize the run loop.76 std::unique_lock<Lock> lock(m_initializeRunLoopMutex);77 78 if (!m_thread) {79 m_thread = Thread::create("WebCore: Scrolling", [this] {80 WTF::Thread::setCurrentThreadIsUserInteractive();81 initializeRunLoop();82 });83 }84 85 #if PLATFORM(COCOA)86 m_initializeRunLoopConditionVariable.wait(lock, [this]{ return m_threadRunLoop; });87 #else88 m_initializeRunLoopConditionVariable.wait(lock, [this]{ return m_runLoop; });89 #endif90 }91 92 void ScrollingThread::dispatchFunctionsFromScrollingThread()93 {94 ASSERT(isCurrentThread());95 96 Vector<Function<void ()>> functions;97 98 {99 auto locker = holdLock(m_functionsMutex);100 functions = WTFMove(m_functions);101 }102 103 for (auto& function : functions)104 function();105 }106 107 #if PLATFORM(IOS_FAMILY)108 NO_RETURN_DUE_TO_ASSERT void ScrollingThread::initializeRunLoop()109 {110 ASSERT_NOT_REACHED();111 }112 113 void ScrollingThread::wakeUpRunLoop()114 {115 }116 117 void ScrollingThread::threadRunLoopSourceCallback(void*)118 {119 }120 121 void ScrollingThread::threadRunLoopSourceCallback()122 {123 }124 #endif // PLATFORM(IOS_FAMILY)125 126 79 } // namespace WebCore 127 80 128 #endif // ENABLE( ASYNC_SCROLLING)81 #endif // ENABLE(SCROLLING_THREAD) -
trunk/Source/WebCore/page/scrolling/ScrollingThread.h
r259805 r261494 26 26 #pragma once 27 27 28 #if ENABLE( ASYNC_SCROLLING)28 #if ENABLE(SCROLLING_THREAD) 29 29 30 30 #include <functional> … … 34 34 #include <wtf/Lock.h> 35 35 #include <wtf/Noncopyable.h> 36 #include <wtf/RunLoop.h> 36 37 #include <wtf/Threading.h> 37 38 #include <wtf/Vector.h> 38 39 #if PLATFORM(COCOA)40 #include <wtf/RetainPtr.h>41 #else42 #include <wtf/RunLoop.h>43 #endif44 39 45 40 namespace WebCore { … … 57 52 58 53 private: 59 friend NeverDestroyed<ScrollingThread>; 54 friend LazyNeverDestroyed<ScrollingThread>; 55 56 static ScrollingThread& singleton(); 60 57 61 58 ScrollingThread(); 62 59 63 static ScrollingThread& singleton();64 65 void createThreadIfNeeded();66 60 void dispatchFunctionsFromScrollingThread(); 67 68 void initializeRunLoop(); 69 void wakeUpRunLoop(); 70 71 #if PLATFORM(COCOA) 72 static void threadRunLoopSourceCallback(void* scrollingThread); 73 void threadRunLoopSourceCallback(); 74 #endif 61 RunLoop& runLoop() { return *m_runLoop; } 75 62 76 63 RefPtr<Thread> m_thread; 77 78 Condition m_initializeRunLoopConditionVariable;79 Lock m_initializeRunLoopMutex;80 81 Lock m_functionsMutex;82 Vector<Function<void ()>> m_functions;83 84 #if PLATFORM(COCOA)85 // FIXME: We should use WebCore::RunLoop here.86 RetainPtr<CFRunLoopRef> m_threadRunLoop;87 RetainPtr<CFRunLoopSourceRef> m_threadRunLoopSource;88 #else89 64 RunLoop* m_runLoop { nullptr }; 90 #endif91 65 }; 92 66 93 67 } // namespace WebCore 94 68 95 #endif // ENABLE( ASYNC_SCROLLING)69 #endif // ENABLE(SCROLLING_THREAD)
Note: See TracChangeset
for help on using the changeset viewer.