Changeset 243979 in webkit
- Timestamp:
- Apr 8, 2019, 3:14:32 AM (7 years ago)
- Location:
- releases/WebKitGTK/webkit-2.24/Source/WebKit
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp (modified) (5 diffs)
-
Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog
r243973 r243979 1 2019-03-01 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [ThreadedCompositor] Simply the compositing run loop worker thread 4 https://bugs.webkit.org/show_bug.cgi?id=195208 5 6 Reviewed by Don Olmstead. 7 8 We can remove the WorkQueuePool, since we never really supported more than one thread, and now that single 9 process model non longer exists it doesn't even make sense. We can simply use a RunLoop instead of a WorkQueue 10 so that the implementation is not specific to the generic WorkQueue implementation. 11 12 * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp: 13 (WebKit::createRunLoop): Helper function to create the RunLoop in a worker thread before m_updateTimer is initialized. 14 (WebKit::CompositingRunLoop::CompositingRunLoop): Use createRunLoop(). 15 (WebKit::CompositingRunLoop::~CompositingRunLoop): Stop the worker thread run loop in the next main run loop iteration. 16 (WebKit::CompositingRunLoop::performTask): Use m_runLoop. 17 (WebKit::CompositingRunLoop::performTaskSync): Ditto. 18 (WebKit::WorkQueuePool::singleton): Deleted. 19 (WebKit::WorkQueuePool::dispatch): Deleted. 20 (WebKit::WorkQueuePool::runLoop): Deleted. 21 (WebKit::WorkQueuePool::invalidate): Deleted. 22 (WebKit::WorkQueuePool::WorkQueuePool): Deleted. 23 (WebKit::WorkQueuePool::getOrCreateWorkQueueForContext): Deleted. 24 (): Deleted. 25 * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h: 26 1 27 2019-03-25 Carlos Garcia Campos <cgarcia@igalia.com> 2 28 -
releases/WebKitGTK/webkit-2.24/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp
r229195 r243979 31 31 #include <wtf/HashMap.h> 32 32 #include <wtf/MainThread.h> 33 #include <wtf/ NeverDestroyed.h>34 #include <wtf/ WorkQueue.h>33 #include <wtf/Threading.h> 34 #include <wtf/threads/BinarySemaphore.h> 35 35 36 36 #if USE(GLIB_EVENT_LOOP) … … 40 40 namespace WebKit { 41 41 42 class WorkQueuePool { 43 WTF_MAKE_NONCOPYABLE(WorkQueuePool); 44 friend NeverDestroyed<WorkQueuePool>; 45 public: 46 static WorkQueuePool& singleton() 47 { 48 ASSERT(RunLoop::isMain()); 49 static NeverDestroyed<WorkQueuePool> workQueuePool; 50 return workQueuePool; 51 } 52 53 void dispatch(void* context, Function<void ()>&& function) 54 { 55 ASSERT(RunLoop::isMain()); 56 getOrCreateWorkQueueForContext(context).dispatch(WTFMove(function)); 57 } 58 59 RunLoop& runLoop(void* context) 60 { 61 return getOrCreateWorkQueueForContext(context).runLoop(); 62 } 63 64 void invalidate(void* context) 65 { 66 auto workQueue = m_workQueueMap.take(context); 67 ASSERT(workQueue); 68 if (m_workQueueMap.isEmpty()) { 69 m_sharedWorkQueue = nullptr; 70 m_threadCount = 0; 71 } else if (workQueue->hasOneRef()) 72 m_threadCount--; 73 } 74 75 private: 76 WorkQueuePool() 77 { 78 // FIXME: This is a sane default limit, but it should be configurable somehow. 79 m_threadCountLimit = 1; 80 } 81 82 WorkQueue& getOrCreateWorkQueueForContext(void* context) 83 { 84 auto addResult = m_workQueueMap.add(context, nullptr); 85 if (addResult.isNewEntry) { 86 // FIXME: This is OK for now, and it works for a single-thread limit. But for configurations where more (but not unlimited) 87 // threads could be used, one option would be to use a HashSet here and disperse the contexts across the available threads. 88 if (m_threadCount >= m_threadCountLimit) { 89 ASSERT(m_sharedWorkQueue); 90 addResult.iterator->value = m_sharedWorkQueue; 91 } else { 92 addResult.iterator->value = WorkQueue::create("org.webkit.ThreadedCompositorWorkQueue"); 93 if (!m_threadCount) 94 m_sharedWorkQueue = addResult.iterator->value; 95 m_threadCount++; 96 } 97 } 98 99 return *addResult.iterator->value; 100 } 101 102 HashMap<void*, RefPtr<WorkQueue>> m_workQueueMap; 103 RefPtr<WorkQueue> m_sharedWorkQueue; 104 unsigned m_threadCount { 0 }; 105 unsigned m_threadCountLimit; 106 }; 42 static RunLoop* createRunLoop() 43 { 44 RunLoop* runLoop = nullptr; 45 BinarySemaphore semaphore; 46 Thread::create("org.webkit.ThreadedCompositor", [&] { 47 runLoop = &RunLoop::current(); 48 semaphore.signal(); 49 runLoop->run(); 50 })->detach(); 51 semaphore.wait(); 52 53 return runLoop; 54 } 107 55 108 56 CompositingRunLoop::CompositingRunLoop(Function<void ()>&& updateFunction) 109 : m_updateTimer(WorkQueuePool::singleton().runLoop(this), this, &CompositingRunLoop::updateTimerFired) 57 : m_runLoop(createRunLoop()) 58 , m_updateTimer(*m_runLoop, this, &CompositingRunLoop::updateTimerFired) 110 59 , m_updateFunction(WTFMove(updateFunction)) 111 60 { … … 119 68 { 120 69 ASSERT(RunLoop::isMain()); 121 // Make sure the WorkQueue is deleted after the CompositingRunLoop, because m_updateTimer has a reference 122 // of the WorkQueue run loop. Passing this is not a problem because the pointer will only be used as a 123 // HashMap key by WorkQueuePool. 124 RunLoop::main().dispatch([context = this] { WorkQueuePool::singleton().invalidate(context); }); 70 // Make sure the RunLoop is stopped after the CompositingRunLoop, because m_updateTimer has a reference. 71 RunLoop::main().dispatch([runLoop = makeRef(*m_runLoop)] { 72 runLoop->stop(); 73 runLoop->dispatch([] { 74 RunLoop::current().stop(); 75 }); 76 }); 125 77 } 126 78 … … 128 80 { 129 81 ASSERT(RunLoop::isMain()); 130 WorkQueuePool::singleton().dispatch(this,WTFMove(function));82 m_runLoop->dispatch(WTFMove(function)); 131 83 } 132 84 … … 135 87 ASSERT(RunLoop::isMain()); 136 88 LockHolder locker(m_dispatchSyncConditionMutex); 137 WorkQueuePool::singleton().dispatch(this,[this, function = WTFMove(function)] {89 m_runLoop->dispatch([this, function = WTFMove(function)] { 138 90 function(); 139 91 LockHolder locker(m_dispatchSyncConditionMutex); -
releases/WebKitGTK/webkit-2.24/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h
r220672 r243979 72 72 void updateTimerFired(); 73 73 74 RunLoop* m_runLoop { nullptr }; 74 75 RunLoop::Timer<CompositingRunLoop> m_updateTimer; 75 76 Function<void ()> m_updateFunction; 76 77 Lock m_dispatchSyncConditionMutex; 77 78 Condition m_dispatchSyncCondition; 78 79 79 80 80 struct {
Note:
See TracChangeset
for help on using the changeset viewer.