Changeset 284671 in webkit
- Timestamp:
- Oct 22, 2021, 1:18:15 AM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
Platform/IPC/StreamConnectionWorkQueue.cpp (modified) (4 diffs)
-
Platform/IPC/StreamConnectionWorkQueue.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r284662 r284671 1 2021-10-22 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 StreamConnectionWorkQueue is not thread-safe 4 https://bugs.webkit.org/show_bug.cgi?id=232068 5 6 Reviewed by Wenson Hsieh. 7 8 Make StreamConnectionWorkQueue thread-safe so that 9 addStreamConnection works from multiple threads. 10 In the future, this will be called when a new RemoteDisplayListRecorder is 11 added during the StreamConnectionWorkQueue message processing 12 invocation for RemoteRenderingBackend::createRemoteImageBuffer. 13 14 * Platform/IPC/StreamConnectionWorkQueue.cpp: 15 (IPC::StreamConnectionWorkQueue::~StreamConnectionWorkQueue): 16 (IPC::StreamConnectionWorkQueue::dispatch): 17 (IPC::StreamConnectionWorkQueue::addStreamConnection): 18 (IPC::StreamConnectionWorkQueue::removeStreamConnection): 19 Change semantics so that adding and removing connections during 20 shutdown is ok. This is required for simpler code since 21 during stop we must dispatch all pending messages, but during 22 message code we might have unconditional start listening when 23 the message creates a new RemoteDisplayListRecorder. 24 As a consequence it's not an error to add a connection, 25 stop and destroy the work queue without removing it. 26 (IPC::StreamConnectionWorkQueue::stop): 27 (IPC::StreamConnectionWorkQueue::startProcessingThread): 28 (IPC::StreamConnectionWorkQueue::wakeUpProcessingThread): Deleted. 29 * Platform/IPC/StreamConnectionWorkQueue.h: 30 1 31 2021-10-21 Alex Christensen <achristensen@webkit.org> 2 32 -
trunk/Source/WebKit/Platform/IPC/StreamConnectionWorkQueue.cpp
r284427 r284671 34 34 } 35 35 36 StreamConnectionWorkQueue::~StreamConnectionWorkQueue() 37 { 38 // `StreamConnectionWorkQueue::stop()` should be called if anything has been dispatched or listened to. 39 ASSERT(!m_processingThread); 40 } 41 36 42 void StreamConnectionWorkQueue::dispatch(WTF::Function<void()>&& function) 37 43 { 44 ASSERT(!m_shouldQuit); // Re-entering during shutdown not supported. 38 45 { 39 46 Locker locker { m_lock }; 40 47 m_functions.append(WTFMove(function)); 41 ASSERT(!m_shouldQuit); // Re-entering during shutdown not supported. 48 if (!m_shouldQuit && !m_processingThread) { 49 startProcessingThread(); 50 return; 51 } 42 52 } 43 wakeUpProcessingThread(); 53 wakeUp(); 54 } 44 55 45 }46 56 void StreamConnectionWorkQueue::addStreamConnection(StreamServerConnectionBase& connection) 47 57 { … … 49 59 Locker locker { m_lock }; 50 60 m_connections.add(connection); 51 ASSERT(!m_shouldQuit); // Re-entering during shutdown not supported. 61 if (!m_shouldQuit && !m_processingThread) { 62 startProcessingThread(); 63 return; 64 } 52 65 } 53 wakeUp ProcessingThread();66 wakeUp(); 54 67 } 55 68 56 69 void StreamConnectionWorkQueue::removeStreamConnection(StreamServerConnectionBase& connection) 57 70 { 58 ASSERT(m_processingThread);59 71 { 60 72 Locker locker { m_lock }; 61 73 m_connections.remove(connection); 62 ASSERT(!m_shouldQuit); // Re-entering during shutdown not supported.63 74 } 64 m_wakeUpSemaphore.signal();75 wakeUp(); 65 76 } 66 77 … … 68 79 { 69 80 m_shouldQuit = true; 70 if (!m_processingThread) 81 RefPtr<Thread> processingThread; 82 { 83 Locker locker { m_lock }; 84 processingThread = WTFMove(m_processingThread); 85 } 86 if (!processingThread) 71 87 return; 72 m_wakeUpSemaphore.signal();73 m_processingThread->waitForCompletion();74 m_processingThread = nullptr;88 ASSERT(Thread::current().uid() != processingThread->uid()); 89 wakeUp(); 90 processingThread->waitForCompletion(); 75 91 } 76 92 … … 85 101 } 86 102 87 void StreamConnectionWorkQueue:: wakeUpProcessingThread()103 void StreamConnectionWorkQueue::startProcessingThread() 88 104 { 89 if (m_processingThread) {90 m_wakeUpSemaphore.signal();91 return;92 }93 94 105 auto task = [this]() mutable { 95 106 for (;;) { -
trunk/Source/WebKit/Platform/IPC/StreamConnectionWorkQueue.h
r284427 r284671 45 45 46 46 StreamConnectionWorkQueue(const char*); 47 ~StreamConnectionWorkQueue() = default;47 ~StreamConnectionWorkQueue(); 48 48 void addStreamConnection(StreamServerConnectionBase&); 49 49 void removeStreamConnection(StreamServerConnectionBase&); … … 56 56 Semaphore& wakeUpSemaphore(); 57 57 private: 58 void wakeUpProcessingThread();58 void startProcessingThread() WTF_REQUIRES_LOCK(m_lock); 59 59 void processStreams(); 60 60 … … 62 62 63 63 Semaphore m_wakeUpSemaphore; 64 RefPtr<Thread> m_processingThread;65 66 64 std::atomic<bool> m_shouldQuit { false }; 67 65 68 66 Lock m_lock; 67 RefPtr<Thread> m_processingThread WTF_GUARDED_BY_LOCK(m_lock); 69 68 Deque<Function<void()>> m_functions WTF_GUARDED_BY_LOCK(m_lock); 70 69 HashSet<Ref<StreamServerConnectionBase>> m_connections WTF_GUARDED_BY_LOCK(m_lock);
Note:
See TracChangeset
for help on using the changeset viewer.