Changeset 229554 in webkit
- Timestamp:
- Mar 12, 2018 2:59:32 PM (6 years ago)
- Location:
- branches/safari-605-branch/Source
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-605-branch/Source/WebCore/ChangeLog
r229553 r229554 1 2018-03-11 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r229028. rdar://problem/37992284 4 5 2018-02-26 Youenn Fablet <youenn@apple.com> 6 7 MessagePort is not always destroyed in the right thread 8 https://bugs.webkit.org/show_bug.cgi?id=183053 9 10 Reviewed by Chris Dumez. 11 12 Make existingMessagePortForIdentifier take a lambda so that we hold the lock until there 13 is no longer a need to keep the MessagePort around. 14 This is very time sensitive and does not happen a lot when running WPT tests. 15 16 Update existing call sites to pass a lambda. 17 18 * dom/MessagePort.cpp: 19 (WebCore::MessagePort::existingMessagePortForIdentifier): 20 * dom/MessagePort.h: 21 * dom/messageports/MessagePortChannelProviderImpl.cpp: 22 (WebCore::MessagePortChannelProviderImpl::postMessageToRemote): 23 (WebCore::MessagePortChannelProviderImpl::checkProcessLocalPortForActivity): 24 1 25 2018-03-11 Jason Marcell <jmarcell@apple.com> 2 26 -
branches/safari-605-branch/Source/WebCore/dom/MessagePort.cpp
r227470 r229554 57 57 void MessagePort::deref() const 58 58 { 59 // MessagePort::existingMessagePortForIdentifier() is unique in that it holds a raw pointer to a MessagePort 60 // but might create a RefPtr from it. 61 // If that happens on one thread at the same time that a MessagePort is being deref'ed and destroyed on a 62 // different thread then Bad Things could happen. 63 // This custom deref() function is designed to handle that contention by guaranteeing that nobody can be 64 // creating a RefPtr inside existingMessagePortForIdentifier while the object is mid-deletion. 59 // This custom deref() function ensures that as long as the lock to allMessagePortsLock is taken, no MessagePort will be destroyed. 60 // This allows isExistingMessagePortLocallyReachable and notifyMessageAvailable to easily query the map and manipulate MessagePort instances. 65 61 66 62 if (!--m_refCount) { … … 75 71 } 76 72 77 RefPtr<MessagePort> MessagePort::existingMessagePortForIdentifier(const MessagePortIdentifier& identifier)73 bool MessagePort::isExistingMessagePortLocallyReachable(const MessagePortIdentifier& identifier) 78 74 { 79 75 Locker<Lock> locker(allMessagePortsLock()); 80 81 return allMessagePorts().get(identifier); 76 auto* port = allMessagePorts().get(identifier); 77 return port && port->isLocallyReachable(); 78 } 79 80 void MessagePort::notifyMessageAvailable(const MessagePortIdentifier& identifier) 81 { 82 Locker<Lock> locker(allMessagePortsLock()); 83 if (auto* port = allMessagePorts().get(identifier)) 84 port->messageAvailable(); 85 82 86 } 83 87 -
branches/safari-605-branch/Source/WebCore/dom/MessagePort.h
r227397 r229554 58 58 static ExceptionOr<TransferredMessagePortArray> disentanglePorts(Vector<RefPtr<MessagePort>>&&); 59 59 static Vector<RefPtr<MessagePort>> entanglePorts(ScriptExecutionContext&, TransferredMessagePortArray&&); 60 WEBCORE_EXPORT static RefPtr<MessagePort> existingMessagePortForIdentifier(const MessagePortIdentifier&); 60 61 WEBCORE_EXPORT static bool isExistingMessagePortLocallyReachable(const MessagePortIdentifier&); 62 WEBCORE_EXPORT static void notifyMessageAvailable(const MessagePortIdentifier&); 61 63 62 64 WEBCORE_EXPORT void messageAvailable(); -
branches/safari-605-branch/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp
r227774 r229554 83 83 { 84 84 performActionOnMainThread([registry = &m_registry, message = WTFMove(message), remoteTarget]() mutable { 85 bool wasFirstMessageInQueue = registry->didPostMessageToRemote(WTFMove(message), remoteTarget); 86 if (wasFirstMessageInQueue) { 87 if (auto remotePort = MessagePort::existingMessagePortForIdentifier(remoteTarget)) 88 remotePort->messageAvailable(); 89 } 85 if (registry->didPostMessageToRemote(WTFMove(message), remoteTarget)) 86 MessagePort::notifyMessageAvailable(remoteTarget); 90 87 }); 91 88 } … … 120 117 ASSERT(isMainThread()); 121 118 122 auto port = MessagePort::existingMessagePortForIdentifier(identifier); 123 if (!port) { 124 callback(MessagePortChannelProvider::HasActivity::No); 125 return; 126 } 127 128 callback(port->isLocallyReachable() ? HasActivity::Yes : HasActivity::No); 119 callback(MessagePort::isExistingMessagePortLocallyReachable(identifier) ? HasActivity::Yes : HasActivity::No); 129 120 } 130 121 -
branches/safari-605-branch/Source/WebKit/ChangeLog
r229039 r229554 1 2018-03-11 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r229028. rdar://problem/37992284 4 5 2018-02-26 Youenn Fablet <youenn@apple.com> 6 7 MessagePort is not always destroyed in the right thread 8 https://bugs.webkit.org/show_bug.cgi?id=183053 9 10 Reviewed by Chris Dumez. 11 12 Update code to pass a lambda to MessagePort::existingMessagePortForIdentifier. 13 14 * WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp: 15 (WebKit::WebMessagePortChannelProvider::checkProcessLocalPortForActivity): 16 * WebProcess/WebProcess.cpp: 17 (WebKit::WebProcess::messagesAvailableForPort): 18 1 19 2018-02-26 Jason Marcell <jmarcell@apple.com> 2 20 -
branches/safari-605-branch/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp
r227397 r229554 121 121 void WebMessagePortChannelProvider::checkProcessLocalPortForActivity(const MessagePortIdentifier& identifier, uint64_t callbackIdentifier) 122 122 { 123 auto port = MessagePort::existingMessagePortForIdentifier(identifier); 124 WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidCheckProcessLocalPortForActivity(callbackIdentifier, port && port->isLocallyReachable()), 0); 123 WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidCheckProcessLocalPortForActivity { callbackIdentifier, MessagePort::isExistingMessagePortLocallyReachable(identifier) }, 0); 125 124 } 126 125 -
branches/safari-605-branch/Source/WebKit/WebProcess/WebProcess.cpp
r228456 r229554 1071 1071 void WebProcess::messagesAvailableForPort(const MessagePortIdentifier& identifier) 1072 1072 { 1073 auto port = MessagePort::existingMessagePortForIdentifier(identifier); 1074 if (port) 1075 port->messageAvailable(); 1073 MessagePort::notifyMessageAvailable(identifier); 1076 1074 } 1077 1075
Note: See TracChangeset
for help on using the changeset viewer.