Changeset 247218 in webkit
- Timestamp:
- Jul 8, 2019 11:26:47 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r247205 r247218 1 2019-07-08 Chris Dumez <cdumez@apple.com> 2 3 Add threading assertion to WTF::CompletionHandler 4 https://bugs.webkit.org/show_bug.cgi?id=199516 5 6 Reviewed by Alex Christensen. 7 8 Add threading assertion to WTF::CompletionHandler to try and catch common cases 9 of unsafe usage (completion handler constructed on one thread but called on 10 another). 11 12 * wtf/CompletionHandler.h: 13 (WTF::CompletionHandler<Out): 14 1 15 2019-07-08 Antoine Quint <graouts@apple.com> 2 16 -
trunk/Source/WTF/wtf/CompletionHandler.h
r245024 r247218 27 27 28 28 #include <wtf/Function.h> 29 #include <wtf/MainThread.h> 29 30 30 31 namespace WTF { … … 41 42 CompletionHandler(CallableType&& callable) 42 43 : m_function(WTFMove(callable)) 44 #if !ASSERT_DISABLED 45 , m_wasConstructedOnMainThread(isMainThread()) 46 #endif 43 47 { 44 48 } … … 56 60 Out operator()(In... in) 57 61 { 62 ASSERT(m_wasConstructedOnMainThread == isMainThread()); 58 63 ASSERT_WITH_MESSAGE(m_function, "Completion handler should not be called more than once"); 59 64 return std::exchange(m_function, nullptr)(std::forward<In>(in)...); … … 62 67 private: 63 68 Function<Out(In...)> m_function; 69 #if !ASSERT_DISABLED 70 bool m_wasConstructedOnMainThread; 71 #endif 64 72 }; 65 73 -
trunk/Source/WebCore/ChangeLog
r247215 r247218 1 2019-07-08 Chris Dumez <cdumez@apple.com> 2 3 Add threading assertion to WTF::CompletionHandler 4 https://bugs.webkit.org/show_bug.cgi?id=199516 5 6 Reviewed by Alex Christensen. 7 8 Update some MessagePort-related code to use WTF::Function instead of WTF::CompletionHandler 9 since the callback is always called on the main thread, even when it was created on a 10 worker thread. Ideally, this code would be refactored so that the callback gets called on 11 the worker thread directly. 12 13 * dom/messageports/MessagePortChannel.cpp: 14 (WebCore::MessagePortChannel::checkRemotePortForActivity): 15 * dom/messageports/MessagePortChannel.h: 16 * dom/messageports/MessagePortChannelProvider.h: 17 * dom/messageports/MessagePortChannelProviderImpl.cpp: 18 (WebCore::MessagePortChannelProviderImpl::checkRemotePortForActivity): 19 * dom/messageports/MessagePortChannelProviderImpl.h: 20 * dom/messageports/MessagePortChannelRegistry.cpp: 21 (WebCore::MessagePortChannelRegistry::checkRemotePortForActivity): 22 * dom/messageports/MessagePortChannelRegistry.h: 23 1 24 2019-07-08 Charlie Turner <cturner@igalia.com> 2 25 -
trunk/Source/WebCore/dom/messageports/MessagePortChannel.cpp
r239427 r247218 183 183 } 184 184 185 void MessagePortChannel::checkRemotePortForActivity(const MessagePortIdentifier& remotePort, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback)185 void MessagePortChannel::checkRemotePortForActivity(const MessagePortIdentifier& remotePort, Function<void(MessagePortChannelProvider::HasActivity)>&& callback) 186 186 { 187 187 ASSERT(isMainThread()); … … 208 208 } 209 209 210 auto outerCallback = CompletionHandler<void(MessagePortChannelProvider::HasActivity)> { [this, protectedThis = makeRef(*this), callback = WTFMove(callback)] (MessagePortChannelProvider::HasActivity hasActivity) mutable {210 auto outerCallback = Function<void(MessagePortChannelProvider::HasActivity)> { [this, protectedThis = makeRef(*this), callback = WTFMove(callback)] (MessagePortChannelProvider::HasActivity hasActivity) mutable { 211 211 if (hasActivity == MessagePortChannelProvider::HasActivity::Yes) { 212 212 callback(hasActivity); -
trunk/Source/WebCore/dom/messageports/MessagePortChannel.h
r240640 r247218 55 55 56 56 void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&); 57 void checkRemotePortForActivity(const MessagePortIdentifier&, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback);57 void checkRemotePortForActivity(const MessagePortIdentifier&, Function<void(MessagePortChannelProvider::HasActivity)>&& callback); 58 58 59 59 WEBCORE_EXPORT bool hasAnyMessagesPendingOrInFlight() const; -
trunk/Source/WebCore/dom/messageports/MessagePortChannelProvider.h
r240640 r247218 47 47 virtual void messagePortDisentangled(const MessagePortIdentifier& local) = 0; 48 48 virtual void messagePortClosed(const MessagePortIdentifier& local) = 0; 49 50 // FIXME: Ideally the callback would be a CompletionHandler but it is always called on the caller's 51 // thread at the moment. 49 52 virtual void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&) = 0; 53 50 54 virtual void postMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget) = 0; 51 55 … … 54 58 No, 55 59 }; 56 virtual void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) = 0; 60 // FIXME: Ideally the callback would be a CompletionHandler but it is always called on the caller's 61 // thread at the moment. 62 virtual void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) = 0; 57 63 58 64 // Operations that the coordinating process performs (e.g. the UIProcess) -
trunk/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp
r234332 r247218 101 101 } 102 102 103 void MessagePortChannelProviderImpl::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& outerCallback)103 void MessagePortChannelProviderImpl::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& outerCallback) 104 104 { 105 auto callback = CompletionHandler<void(HasActivity)> { [outerCallback = WTFMove(outerCallback)](HasActivity hasActivity) mutable {105 auto callback = Function<void(HasActivity)> { [outerCallback = WTFMove(outerCallback)](HasActivity hasActivity) mutable { 106 106 ASSERT(isMainThread()); 107 107 outerCallback(hasActivity); -
trunk/Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.h
r227737 r247218 43 43 void postMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget) final; 44 44 void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&) final; 45 void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final;45 void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) final; 46 46 47 47 void checkProcessLocalPortForActivity(const MessagePortIdentifier&, ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final; -
trunk/Source/WebCore/dom/messageports/MessagePortChannelRegistry.cpp
r237828 r247218 158 158 } 159 159 160 void MessagePortChannelRegistry::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback)160 void MessagePortChannelRegistry::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(MessagePortChannelProvider::HasActivity)>&& callback) 161 161 { 162 162 ASSERT(isMainThread()); -
trunk/Source/WebCore/dom/messageports/MessagePortChannelRegistry.h
r240640 r247218 45 45 WEBCORE_EXPORT bool didPostMessageToRemote(MessageWithMessagePorts&&, const MessagePortIdentifier& remoteTarget); 46 46 WEBCORE_EXPORT void takeAllMessagesForPort(const MessagePortIdentifier&, Function<void(Vector<MessageWithMessagePorts>&&, Function<void()>&&)>&&); 47 WEBCORE_EXPORT void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(MessagePortChannelProvider::HasActivity)>&& callback);47 WEBCORE_EXPORT void checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(MessagePortChannelProvider::HasActivity)>&& callback); 48 48 49 49 WEBCORE_EXPORT MessagePortChannel* existingChannelContainingPort(const MessagePortIdentifier&); -
trunk/Source/WebKit/ChangeLog
r247212 r247218 1 2019-07-08 Chris Dumez <cdumez@apple.com> 2 3 Add threading assertion to WTF::CompletionHandler 4 https://bugs.webkit.org/show_bug.cgi?id=199516 5 6 Reviewed by Alex Christensen. 7 8 Update some MessagePort-related code to use WTF::Function instead of WTF::CompletionHandler 9 since the callback is always called on the main thread, even when it was created on a 10 worker thread. Ideally, this code would be refactored so that the callback gets called on 11 the worker thread directly. 12 13 * UIProcess/UIMessagePortChannelProvider.cpp: 14 (WebKit::UIMessagePortChannelProvider::checkRemotePortForActivity): 15 * UIProcess/UIMessagePortChannelProvider.h: 16 * WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp: 17 (WebKit::WebMessagePortChannelProvider::checkRemotePortForActivity): 18 * WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h: 19 1 20 2019-07-08 Antoine Quint <graouts@apple.com> 2 21 -
trunk/Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp
r235265 r247218 86 86 } 87 87 88 void UIMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier&, CompletionHandler<void(HasActivity)>&&)88 void UIMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier&, Function<void(HasActivity)>&&) 89 89 { 90 90 // Should never be called in the UI process provider. -
trunk/Source/WebKit/UIProcess/UIMessagePortChannelProvider.h
r227340 r247218 46 46 void takeAllMessagesForPort(const WebCore::MessagePortIdentifier&, Function<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>&&) final; 47 47 void postMessageToRemote(WebCore::MessageWithMessagePorts&&, const WebCore::MessagePortIdentifier& remoteTarget) final; 48 void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final;48 void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) final; 49 49 void checkProcessLocalPortForActivity(const WebCore::MessagePortIdentifier&, WebCore::ProcessIdentifier, CompletionHandler<void(HasActivity)>&&) final; 50 50 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp
r235205 r247218 129 129 } 130 130 131 void WebMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& completionHandler)131 void WebMessagePortChannelProvider::checkRemotePortForActivity(const MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& completionHandler) 132 132 { 133 133 static std::atomic<uint64_t> currentHandlerIdentifier; … … 136 136 { 137 137 Locker<Lock> locker(m_remoteActivityCallbackLock); 138 auto result = m_remoteActivityCallbacks.ensure(identifier, [completionHandler = WTFMove(completionHandler)]() mutable { 139 return WTFMove(completionHandler); 140 }); 141 ASSERT_UNUSED(result, result.isNewEntry); 138 ASSERT(!m_remoteActivityCallbacks.contains(identifier)); 139 m_remoteActivityCallbacks.set(identifier, WTFMove(completionHandler)); 142 140 } 143 141 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h
r227340 r247218 53 53 54 54 // To be called only in the UI process 55 void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, CompletionHandler<void(HasActivity)>&& callback) final;55 void checkRemotePortForActivity(const WebCore::MessagePortIdentifier& remoteTarget, Function<void(HasActivity)>&& callback) final; 56 56 57 57 Lock m_takeAllMessagesCallbackLock; 58 HashMap<uint64_t, CompletionHandler<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>> m_takeAllMessagesCallbacks;58 HashMap<uint64_t, Function<void(Vector<WebCore::MessageWithMessagePorts>&&, Function<void()>&&)>> m_takeAllMessagesCallbacks; 59 59 Lock m_remoteActivityCallbackLock; 60 HashMap<uint64_t, CompletionHandler<void(HasActivity)>> m_remoteActivityCallbacks;60 HashMap<uint64_t, Function<void(HasActivity)>> m_remoteActivityCallbacks; 61 61 }; 62 62
Note: See TracChangeset
for help on using the changeset viewer.