Changeset 229554 in webkit


Ignore:
Timestamp:
Mar 12, 2018 2:59:32 PM (6 years ago)
Author:
jmarcell@apple.com
Message:

Cherry-pick r229028. rdar://problem/37992284

Location:
branches/safari-605-branch/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-605-branch/Source/WebCore/ChangeLog

    r229553 r229554  
     12018-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
    1252018-03-11  Jason Marcell  <jmarcell@apple.com>
    226
  • branches/safari-605-branch/Source/WebCore/dom/MessagePort.cpp

    r227470 r229554  
    5757void MessagePort::deref() const
    5858{
    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.
    6561
    6662    if (!--m_refCount) {
     
    7571}
    7672
    77 RefPtr<MessagePort> MessagePort::existingMessagePortForIdentifier(const MessagePortIdentifier& identifier)
     73bool MessagePort::isExistingMessagePortLocallyReachable(const MessagePortIdentifier& identifier)
    7874{
    7975    Locker<Lock> locker(allMessagePortsLock());
    80 
    81     return allMessagePorts().get(identifier);
     76    auto* port = allMessagePorts().get(identifier);
     77    return port && port->isLocallyReachable();
     78}
     79
     80void MessagePort::notifyMessageAvailable(const MessagePortIdentifier& identifier)
     81{
     82    Locker<Lock> locker(allMessagePortsLock());
     83    if (auto* port = allMessagePorts().get(identifier))
     84        port->messageAvailable();
     85
    8286}
    8387
  • branches/safari-605-branch/Source/WebCore/dom/MessagePort.h

    r227397 r229554  
    5858    static ExceptionOr<TransferredMessagePortArray> disentanglePorts(Vector<RefPtr<MessagePort>>&&);
    5959    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&);
    6163
    6264    WEBCORE_EXPORT void messageAvailable();
  • branches/safari-605-branch/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp

    r227774 r229554  
    8383{
    8484    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);
    9087    });
    9188}
     
    120117    ASSERT(isMainThread());
    121118
    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);
    129120}
    130121
  • branches/safari-605-branch/Source/WebKit/ChangeLog

    r229039 r229554  
     12018-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
    1192018-02-26  Jason Marcell  <jmarcell@apple.com>
    220
  • branches/safari-605-branch/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp

    r227397 r229554  
    121121void WebMessagePortChannelProvider::checkProcessLocalPortForActivity(const MessagePortIdentifier& identifier, uint64_t callbackIdentifier)
    122122{
    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);
    125124}
    126125
  • branches/safari-605-branch/Source/WebKit/WebProcess/WebProcess.cpp

    r228456 r229554  
    10711071void WebProcess::messagesAvailableForPort(const MessagePortIdentifier& identifier)
    10721072{
    1073     auto port = MessagePort::existingMessagePortForIdentifier(identifier);
    1074     if (port)
    1075         port->messageAvailable();
     1073    MessagePort::notifyMessageAvailable(identifier);
    10761074}
    10771075
Note: See TracChangeset for help on using the changeset viewer.