WebKit Bugzilla
Attachment 373536 Details for
Bug 199516
: Add threading assertion to WTF::CompletionHandler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP Patch
199516_wip.patch (text/plain), 13.18 KB, created by
Chris Dumez
on 2019-07-05 14:17:12 PDT
(
hide
)
Description:
WIP Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2019-07-05 14:17:12 PDT
Size:
13.18 KB
patch
obsolete
>diff --git a/Source/WTF/wtf/CompletionHandler.h b/Source/WTF/wtf/CompletionHandler.h >index fda54a6aad0..b0506c204d0 100644 >--- a/Source/WTF/wtf/CompletionHandler.h >+++ b/Source/WTF/wtf/CompletionHandler.h >@@ -26,6 +26,7 @@ > #pragma once > > #include <wtf/Function.h> >+#include <wtf/MainThread.h> > > namespace WTF { > >@@ -40,6 +41,7 @@ public: > template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type> > CompletionHandler(CallableType&& callable) > : m_function(WTFMove(callable)) >+ , m_wasConstructedOnMainThread(isMainThread()) > { > } > >@@ -55,12 +57,14 @@ public: > > Out operator()(In... in) > { >+ RELEASE_ASSERT(m_wasConstructedOnMainThread == isMainThread()); // FIXME: Make it a debug ASSERT(). > ASSERT_WITH_MESSAGE(m_function, "Completion handler should not be called more than once"); > return std::exchange(m_function, nullptr)(std::forward<In>(in)...); > } > > private: > Function<Out(In...)> m_function; >+ bool m_wasConstructedOnMainThread; > }; > > namespace Detail { >diff --git a/Source/WebCore/dom/messageports/MessagePortChannel.cpp b/Source/WebCore/dom/messageports/MessagePortChannel.cpp >index 9cf54974cc5..a5b60d98bb4 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannel.cpp >+++ b/Source/WebCore/dom/messageports/MessagePortChannel.cpp >@@ -182,7 +182,7 @@ void MessagePortChannel::takeAllMessagesForPort(const MessagePortIdentifier& por > }); > } > >-void MessagePortChannel::checkRemotePortForActivity(const MessagePortIdentifier& remotePort, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback) >+void MessagePortChannel::checkRemotePortForActivity(const MessagePortIdentifier& remotePort, Function<void(MessagePortChannelProvider::HasActivity)>&& callback) > { > ASSERT(isMainThread()); > ASSERT(remotePort == m_ports[0] || remotePort == m_ports[1]); >@@ -207,7 +207,7 @@ void MessagePortChannel::checkRemotePortForActivity(const MessagePortIdentifier& > return; > } > >- auto outerCallback = CompletionHandler<void(MessagePortChannelProvider::HasActivity)> { [this, protectedThis = makeRef(*this), callback = WTFMove(callback)] (MessagePortChannelProvider::HasActivity hasActivity) mutable { >+ auto outerCallback = Function<void(MessagePortChannelProvider::HasActivity)> { [this, protectedThis = makeRef(*this), callback = WTFMove(callback)] (MessagePortChannelProvider::HasActivity hasActivity) mutable { > if (hasActivity == MessagePortChannelProvider::HasActivity::Yes) { > callback(hasActivity); > return; >diff --git a/Source/WebCore/dom/messageports/MessagePortChannel.h b/Source/WebCore/dom/messageports/MessagePortChannel.h >index 05f6945227d..cc2994d2f92 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannel.h >+++ b/Source/WebCore/dom/messageports/MessagePortChannel.h >@@ -54,7 +54,7 @@ public: > bool postMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget); > > void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&); >- void checkRemotePortForActivity(const MessagePortIdentifier&, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback); >+ void checkRemotePortForActivity(const MessagePortIdentifier&, Function<void(MessagePortChannelProvider::HasActivity)>&& callback); > > WEBCORE_EXPORT bool hasAnyMessagesPendingOrInFlight() const; > >diff --git a/Source/WebCore/dom/messageports/MessagePortChannelProvider.h b/Source/WebCore/dom/messageports/MessagePortChannelProvider.h >index 0c145a7ce0e..238edaadaf5 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannelProvider.h >+++ b/Source/WebCore/dom/messageports/MessagePortChannelProvider.h >@@ -53,7 +53,7 @@ public: > Yes, > No, > }; >- virtual void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) = 0; >+ virtual void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) = 0; > > // Operations that the coordinating process performs (e.g. the UIProcess) > virtual void checkProcessLocalPortForActivity(const MessagePortIdentifier&, ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) = 0; >diff --git a/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp b/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp >index e74d99a5e9f..0b07c2753a9 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp >+++ b/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp >@@ -100,9 +100,9 @@ void MessagePortChannelProviderImpl::takeAllMessagesForPort(const MessagePortIde > }); > } > >-void MessagePortChannelProviderImpl::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& outerCallback) >+void MessagePortChannelProviderImpl::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& outerCallback) > { >- auto callback = CompletionHandler<void(HasActivity)> { [outerCallback = WTFMove(outerCallback)](HasActivity hasActivity) mutable { >+ auto callback = Function<void(HasActivity)> { [outerCallback = WTFMove(outerCallback)](HasActivity hasActivity) mutable { > ASSERT(isMainThread()); > outerCallback(hasActivity); > } }; >diff --git a/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.h b/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.h >index 28f6ad5bcfb..d3554e1aa1d 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.h >+++ b/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.h >@@ -42,7 +42,7 @@ private: > void messagePortClosed(const MessagePortIdentifier& local) final; > void postMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget) final; > void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&) final; >- void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final; >+ void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) final; > > void checkProcessLocalPortForActivity(const MessagePortIdentifier&, ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final; > >diff --git a/Source/WebCore/dom/messageports/MessagePortChannelRegistry.cpp b/Source/WebCore/dom/messageports/MessagePortChannelRegistry.cpp >index e1d2f82aba4..1cb35546e33 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannelRegistry.cpp >+++ b/Source/WebCore/dom/messageports/MessagePortChannelRegistry.cpp >@@ -157,7 +157,7 @@ void MessagePortChannelRegistry::takeAllMessagesForPort(const MessagePortIdentif > channel->takeAllMessagesForPort(port, WTFMove(callback)); > } > >-void MessagePortChannelRegistry::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback) >+void MessagePortChannelRegistry::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(MessagePortChannelProvider::HasActivity)>&& callback) > { > ASSERT(isMainThread()); > >diff --git a/Source/WebCore/dom/messageports/MessagePortChannelRegistry.h b/Source/WebCore/dom/messageports/MessagePortChannelRegistry.h >index 916e5e05a41..531aa958484 100644 >--- a/Source/WebCore/dom/messageports/MessagePortChannelRegistry.h >+++ b/Source/WebCore/dom/messageports/MessagePortChannelRegistry.h >@@ -44,7 +44,7 @@ public: > WEBCORE_EXPORT void didCloseMessagePort(const MessagePortIdentifier& local); > WEBCORE_EXPORT bool didPostMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget); > WEBCORE_EXPORT void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&); >- WEBCORE_EXPORT void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback); >+ WEBCORE_EXPORT void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(MessagePortChannelProvider::HasActivity)>&& callback); > > WEBCORE_EXPORT MessagePortChannel* existingChannelContainingPort(const MessagePortIdentifier&); > >diff --git a/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp b/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp >index f990820ec26..fb4c644be2a 100644 >--- a/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp >+++ b/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp >@@ -85,7 +85,7 @@ void UIMessagePortChannelProvider::postMessageToRemote(MessageWithMessagePorts&& > ASSERT_NOT_REACHED(); > } > >-void UIMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier&, CompletionHandler<void(HasActivity)>&&) >+void UIMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier&, Function<void(HasActivity)>&&) > { > // Should never be called in the UI process provider. > ASSERT_NOT_REACHED(); >diff --git a/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h b/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h >index f1e0c49c1d3..6c269604a28 100644 >--- a/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h >+++ b/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h >@@ -45,7 +45,7 @@ private: > void messagePortClosed(const WebCore::MessagePortIdentifier& local) final; > void takeAllMessagesForPort(const WebCore::MessagePortIdentifier&, Function<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>&&) final; > void postMessageToRemote(WebCore::MessageWithMessagePorts&&, const WebCore::MessagePortIdentifier& remoteTarget) final; >- void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final; >+ void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) final; > void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, WebCore::ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final; > > WebCore::MessagePortChannelRegistry m_registry; >diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp >index 4ba3c08c7d5..6d2856a04ed 100644 >--- a/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp >+++ b/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp >@@ -128,17 +128,15 @@ void WebMessagePortChannelProvider::checkProcessLocalPortForActivity(const Messa > ASSERT_NOT_REACHED(); > } > >-void WebMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& completionHandler) >+void WebMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& completionHandler) > { > static std::atomic<uint64_t> currentHandlerIdentifier; > uint64_t identifier = ++currentHandlerIdentifier; > > { > Locker<Lock> locker(m_remoteActivityCallbackLock); >- auto result = m_remoteActivityCallbacks.ensure(identifier, [completionHandler = WTFMove(completionHandler)]() mutable { >- return WTFMove(completionHandler); >- }); >- ASSERT_UNUSED(result, result.isNewEntry); >+ ASSERT(!m_remoteActivityCallbacks.contains(identifier)); >+ m_remoteActivityCallbacks.set(identifier, WTFMove(completionHandler)); > } > > WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::CheckRemotePortForActivity(remoteTarget, identifier), 0); >diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h b/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h >index 6c9cf864017..533be840cad 100644 >--- a/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h >+++ b/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h >@@ -52,12 +52,12 @@ private: > void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, WebCore::ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final; > > // To be called only in the UI process >- void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final; >+ void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) final; > > Lock m_takeAllMessagesCallbackLock; >- HashMap<uint64_t, CompletionHandler<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>> m_takeAllMessagesCallbacks; >+ HashMap<uint64_t, Function<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>> m_takeAllMessagesCallbacks; > Lock m_remoteActivityCallbackLock; >- HashMap<uint64_t, CompletionHandler<void(HasActivity)>> m_remoteActivityCallbacks; >+ HashMap<uint64_t, Function<void(HasActivity)>> m_remoteActivityCallbacks; > }; > > } // namespace WebKit
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 199516
:
373493
|
373497
|
373506
|
373509
|
373513
|
373514
|
373528
|
373530
|
373536
|
373549
|
373641