Changeset 201482 in webkit
- Timestamp:
- May 27, 2016, 10:51:42 PM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 60 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r201479 r201482 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 callOnMainThread() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158166 5 6 Reviewed by Brady Eidson. 7 8 callOnMainThread() should not copy captured lambda variables. This 9 function is usually called cross-thread with a lambda and copying 10 the lambda (and its captured variables) can lead to thread-safety 11 issues. 12 13 This patch updates callOnMainThread() to take a NoncopyableFunction&& 14 in parameter instead of a std::function. The call sites of 15 callOnMainThread() have also been updated to use C++14's lambda 16 capture with initializer. 17 18 * WTF.xcodeproj/project.pbxproj: 19 20 * wtf/FunctionDispatcher.h: 21 * wtf/NoncopyableFunction.h: 22 - Moved NoncopyableFunction from FunctionDispatcher.h to 23 NoncopyableFunction.h. 24 - Add a new operator=(nullptr_t) operator to NoncopyableFunction to 25 match std::function, as one of the call sites needed it. 26 27 * wtf/MainThread.cpp: 28 (WTF::functionQueue): 29 (WTF::dispatchFunctionsFromMainThread): 30 (WTF::callOnMainThread): 31 * wtf/MainThread.h: 32 1 33 2016-05-27 Yusuke Suzuki <utatane.tea@gmail.com> 2 34 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r201406 r201482 115 115 8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; }; 116 116 8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; }; 117 83F2BADF1CF9524E003E99C3 /* NoncopyableFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 83F2BADE1CF9524E003E99C3 /* NoncopyableFunction.h */; }; 117 118 83FBA93219DF459700F30ADB /* TypeCasts.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FBA93119DF459700F30ADB /* TypeCasts.h */; }; 118 119 86F46F611A2840EE00CCBF22 /* RefCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 86F46F5F1A2840EE00CCBF22 /* RefCounter.h */; }; … … 438 439 8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; }; 439 440 8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; }; 441 83F2BADE1CF9524E003E99C3 /* NoncopyableFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NoncopyableFunction.h; sourceTree = "<group>"; }; 440 442 83FBA93119DF459700F30ADB /* TypeCasts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeCasts.h; sourceTree = "<group>"; }; 441 443 86F46F5F1A2840EE00CCBF22 /* RefCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCounter.h; sourceTree = "<group>"; }; … … 870 872 0F0D85B317234CB100338210 /* NoLock.h */, 871 873 A8A472D0151A825B004123FF /* Noncopyable.h */, 874 83F2BADE1CF9524E003E99C3 /* NoncopyableFunction.h */, 872 875 A8A472D5151A825B004123FF /* NumberOfCores.cpp */, 873 876 A8A472D6151A825B004123FF /* NumberOfCores.h */, … … 1232 1235 A8A473DA151A825B004123FF /* HashTraits.h in Headers */, 1233 1236 A8A473DB151A825B004123FF /* HexNumber.h in Headers */, 1237 83F2BADF1CF9524E003E99C3 /* NoncopyableFunction.h in Headers */, 1234 1238 2684D4361C000D400081D663 /* IndexSparseSet.h in Headers */, 1235 1239 A8A473DC151A825B004123FF /* InlineASM.h in Headers */, -
trunk/Source/WTF/wtf/FunctionDispatcher.h
r201464 r201482 28 28 29 29 #include <functional> 30 #include <wtf/NoncopyableFunction.h> 30 31 #include <wtf/ThreadSafeRefCounted.h> 31 32 32 33 namespace WTF { 33 34 // FIXME: Move this to its own header (e.g. Functional.h).35 // FIXME: We could make this templated to support other lambdas than void() and make this more reusable.36 class NoncopyableFunction {37 public:38 NoncopyableFunction() = default;39 40 template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type>41 NoncopyableFunction(CallableType&& callable)42 : m_callableWrapper(std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable)))43 {44 }45 46 void operator()() const47 {48 if (m_callableWrapper)49 m_callableWrapper->call();50 }51 52 explicit operator bool() const { return !!m_callableWrapper; }53 54 template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type>55 NoncopyableFunction& operator=(CallableType&& callable)56 {57 m_callableWrapper = std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable));58 return *this;59 }60 61 private:62 class CallableWrapperBase {63 WTF_MAKE_FAST_ALLOCATED;64 public:65 virtual ~CallableWrapperBase() { }66 67 virtual void call() = 0;68 };69 70 template<typename CallableType>71 class CallableWrapper final : public CallableWrapperBase {72 public:73 explicit CallableWrapper(CallableType&& callable)74 : m_callable(WTFMove(callable))75 {76 }77 78 CallableWrapper(const CallableWrapper&) = delete;79 CallableWrapper& operator=(const CallableWrapper&) = delete;80 81 void call() final { m_callable(); }82 83 private:84 CallableType m_callable;85 };86 87 std::unique_ptr<CallableWrapperBase> m_callableWrapper;88 };89 34 90 35 // FunctionDispatcher is an abstract representation of something that functions can be … … 104 49 105 50 using WTF::FunctionDispatcher; 106 using WTF::NoncopyableFunction;107 51 108 52 #endif // FunctionDispatcher_h -
trunk/Source/WTF/wtf/MainThread.cpp
r194496 r201482 48 48 static StaticLock mainThreadFunctionQueueMutex; 49 49 50 static Deque< std::function<void ()>>& functionQueue()51 { 52 static NeverDestroyed<Deque< std::function<void ()>>> functionQueue;50 static Deque<NoncopyableFunction>& functionQueue() 51 { 52 static NeverDestroyed<Deque<NoncopyableFunction>> functionQueue; 53 53 return functionQueue; 54 54 } … … 121 121 auto startTime = std::chrono::steady_clock::now(); 122 122 123 std::function<void ()>function;123 NoncopyableFunction function; 124 124 125 125 while (true) { … … 145 145 } 146 146 147 void callOnMainThread( std::function<void ()>function)147 void callOnMainThread(NoncopyableFunction&& function) 148 148 { 149 149 ASSERT(function); -
trunk/Source/WTF/wtf/MainThread.h
r194318 r201482 33 33 #include <functional> 34 34 #include <stdint.h> 35 #include <wtf/NoncopyableFunction.h> 35 36 36 37 namespace WTF { … … 41 42 WTF_EXPORT_PRIVATE void initializeMainThread(); 42 43 43 WTF_EXPORT_PRIVATE void callOnMainThread( std::function<void ()>);44 WTF_EXPORT_PRIVATE void callOnMainThread(NoncopyableFunction&&); 44 45 45 46 #if PLATFORM(COCOA) -
trunk/Source/WTF/wtf/NoncopyableFunction.h
r201481 r201482 1 1 /* 2 * Copyright (C) 201 3Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef FunctionDispatcher_h 27 #define FunctionDispatcher_h 26 #pragma once 28 27 29 #include <functional> 30 #include <wtf/ThreadSafeRefCounted.h> 28 #include <memory> 31 29 32 30 namespace WTF { 33 31 34 // FIXME: Move this to its own header (e.g. Functional.h).35 32 // FIXME: We could make this templated to support other lambdas than void() and make this more reusable. 36 33 class NoncopyableFunction { … … 56 53 { 57 54 m_callableWrapper = std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable)); 55 return *this; 56 } 57 58 NoncopyableFunction& operator=(std::nullptr_t) 59 { 60 m_callableWrapper = nullptr; 58 61 return *this; 59 62 } … … 88 91 }; 89 92 90 // FunctionDispatcher is an abstract representation of something that functions can be91 // dispatched to. This can for example be a run loop or a work queue.92 93 class FunctionDispatcher : public ThreadSafeRefCounted<FunctionDispatcher> {94 public:95 WTF_EXPORT_PRIVATE virtual ~FunctionDispatcher();96 97 virtual void dispatch(NoncopyableFunction&&) = 0;98 99 protected:100 WTF_EXPORT_PRIVATE FunctionDispatcher();101 };102 103 93 } // namespace WTF 104 94 105 using WTF::FunctionDispatcher;106 95 using WTF::NoncopyableFunction; 107 108 #endif // FunctionDispatcher_h -
trunk/Source/WebCore/ChangeLog
r201478 r201482 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 callOnMainThread() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158166 5 6 Reviewed by Brady Eidson. 7 8 callOnMainThread() should not copy captured lambda variables. This 9 function is usually called cross-thread with a lambda and copying 10 the lambda (and its captured variables) can lead to thread-safety 11 issues. 12 13 This patch updates callOnMainThread() to take a NoncopyableFunction&& 14 in parameter instead of a std::function. The call sites of 15 callOnMainThread() have also been updated to use C++14's lambda 16 capture with initializer. 17 18 * Modules/indexeddb/IDBTransaction.cpp: 19 (WebCore::IDBTransaction::putOrAddOnServer): 20 * Modules/mediastream/MediaDevicesRequest.cpp: 21 (WebCore::MediaDevicesRequest::didCompletePermissionCheck): 22 (WebCore::MediaDevicesRequest::didCompleteTrackSourceInfoRequest): 23 * Modules/mediastream/MediaEndpointPeerConnection.cpp: 24 (WebCore::MediaEndpointPeerConnection::runTask): 25 * Modules/mediastream/MediaEndpointPeerConnection.h: 26 * Modules/mediastream/UserMediaRequest.cpp: 27 (WebCore::UserMediaRequest::constraintsValidated): 28 (WebCore::UserMediaRequest::userMediaAccessGranted): 29 * Modules/webaudio/AudioContext.cpp: 30 (WebCore::AudioContext::scheduleNodeDeletion): 31 (WebCore::AudioContext::isPlayingAudioDidChange): 32 * dom/Document.cpp: 33 (WebCore::Document::postTask): 34 (WebCore::Document::pendingTasksTimerFired): Deleted. 35 * dom/ScriptElement.cpp: 36 (WebCore::ScriptElement::requestScript): 37 * fileapi/AsyncFileStream.cpp: 38 (WebCore::callOnFileThread): 39 (WebCore::AsyncFileStream::~AsyncFileStream): 40 (WebCore::AsyncFileStream::perform): 41 * fileapi/AsyncFileStream.h: 42 * fileapi/ThreadableBlobRegistry.cpp: 43 (WebCore::ThreadableBlobRegistry::registerFileBlobURL): 44 (WebCore::ThreadableBlobRegistry::registerBlobURL): 45 (WebCore::ThreadableBlobRegistry::registerBlobURLForSlice): 46 (WebCore::ThreadableBlobRegistry::blobSize): 47 (WebCore::ThreadableBlobRegistry::unregisterBlobURL): 48 (WebCore::ThreadableBlobRegistry::registerBlobURLOptionallyFileBacked): Deleted. 49 * loader/icon/IconDatabase.cpp: 50 (WebCore::IconDatabase::dispatchDidImportIconURLForPageURLOnMainThread): 51 (WebCore::IconDatabase::dispatchDidImportIconDataForPageURLOnMainThread): 52 * page/ResourceUsageThread.cpp: 53 (WebCore::ResourceUsageThread::notifyObservers): 54 (WebCore::ResourceUsageThread::threadBody): 55 * page/ResourceUsageThread.h: 56 * page/scrolling/ScrollingThread.cpp: 57 (WebCore::ScrollingThread::dispatch): 58 (WebCore::ScrollingThread::dispatchBarrier): 59 (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread): 60 * page/scrolling/ScrollingThread.h: 61 * page/scrolling/ios/ScrollingTreeIOS.cpp: 62 (WebCore::ScrollingTreeIOS::invalidate): 63 (WebCore::ScrollingTreeIOS::scrollingTreeNodeDidScroll): 64 (WebCore::ScrollingTreeIOS::currentSnapPointIndicesDidChange): 65 (WebCore::ScrollingTreeIOS::createScrollingTreeNode): Deleted. 66 * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm: 67 (WebCore::ScrollingTreeFrameScrollingNodeMac::releaseReferencesToScrollerImpsOnTheMainThread): 68 * platform/MemoryPressureHandler.cpp: 69 (WebCore::MemoryPressureHandler::releaseMemory): 70 * platform/audio/ios/MediaSessionManagerIOS.mm: 71 (-[WebMediaSessionHelper dealloc]): 72 (-[WebMediaSessionHelper startMonitoringAirPlayRoutes]): 73 (-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]): 74 * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm: 75 (WebCore::AudioSourceProviderAVFObjC::prepare): 76 * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: 77 (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): 78 (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): 79 * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: 80 (-[WebCDMSessionAVFoundationObjCListener observeValueForKeyPath:ofObject:change:context:]): 81 * platform/graphics/avfoundation/objc/MediaPlaybackTargetPickerMac.mm: 82 (-[WebAVOutputDeviceMenuControllerHelper observeValueForKeyPath:ofObject:change:context:]): 83 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: 84 (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): 85 (-[WebCoreAVFMovieObserver legibleOutput:didOutputAttributedStrings:nativeSampleBuffers:forItemTime:]): 86 (-[WebCoreAVFMovieObserver outputSequenceWasFlushed:]): 87 (-[WebCoreAVFLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): 88 (-[WebCoreAVFLoaderDelegate resourceLoader:shouldWaitForResponseToAuthenticationChallenge:]): 89 (-[WebCoreAVFLoaderDelegate resourceLoader:didCancelLoadingRequest:]): 90 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: 91 (WebCore::CMTimebaseEffectiveRateChangedCallback): 92 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): 93 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): 94 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: 95 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: 96 (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): 97 * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: 98 (-[WebAVStreamDataParserListener streamDataParser:didParseStreamDataAsAsset:]): 99 (-[WebAVStreamDataParserListener streamDataParser:didParseStreamDataAsAsset:withDiscontinuity:]): 100 (-[WebAVStreamDataParserListener streamDataParser:didFailToParseStreamDataWithError:]): 101 (-[WebAVStreamDataParserListener streamDataParser:didProvideMediaData:forTrackID:mediaType:flags:]): 102 (-[WebAVStreamDataParserListener streamDataParser:didReachEndOfTrackWithTrackID:mediaType:]): 103 (-[WebAVStreamDataParserListener streamDataParser:didProvideContentKeyRequestInitializationData:forTrackID:]): 104 (-[WebAVSampleBufferErrorListener observeValueForKeyPath:ofObject:change:context:]): 105 (-[WebAVSampleBufferErrorListener layerFailedToDecode:]): 106 * platform/graphics/cg/GraphicsContextCG.cpp: 107 (WebCore::patternReleaseCallback): 108 * platform/graphics/cg/PatternCG.cpp: 109 (WebCore::patternReleaseCallback): 110 * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: 111 (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): 112 (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): 113 (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): 114 * platform/mediastream/MediaStreamPrivate.cpp: 115 (WebCore::MediaStreamPrivate::scheduleDeferredTask): 116 * platform/mediastream/MediaStreamPrivate.h: 117 * platform/mediastream/mac/AVMediaCaptureSource.h: 118 * platform/mediastream/mac/AVMediaCaptureSource.mm: 119 (WebCore::AVMediaCaptureSource::scheduleDeferredTask): 120 * platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp: 121 (WebCore::RealtimeMediaSourceCenterMac::getMediaStreamTrackSources): 122 * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm: 123 (WebCore::WebAudioSourceProviderAVFObjC::prepare): 124 * platform/mock/MockRealtimeMediaSourceCenter.cpp: 125 (WebCore::MockRealtimeMediaSourceCenter::getMediaStreamTrackSources): 126 * platform/network/BlobResourceHandle.cpp: 127 (WebCore::BlobResourceHandle::start): 128 (WebCore::BlobResourceHandle::notifyFinish): 129 * platform/network/DataURLDecoder.cpp: 130 (WebCore::DataURLDecoder::decode): 131 * platform/network/DataURLDecoder.h: 132 * platform/network/cocoa/WebCoreNSURLSession.mm: 133 (-[WebCoreNSURLSession dealloc]): 134 (-[WebCoreNSURLSessionDataTask cancel]): 135 (-[WebCoreNSURLSessionDataTask suspend]): 136 (-[WebCoreNSURLSessionDataTask resume]): 137 * platform/network/curl/CurlDownload.cpp: 138 (WebCore::CurlDownload::didReceiveHeader): 139 (WebCore::CurlDownload::didReceiveData): Deleted. 140 1 141 2016-05-27 Tim Horton <timothy_horton@apple.com> 2 142 -
trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
r201461 r201482 980 980 // In that case, we cannot successfully store this record, so we callback with an error. 981 981 auto result = IDBResultData::error(protectedOperation->identifier(), { IDBDatabaseException::UnknownError, ASCIILiteral("Error preparing Blob/File data to be stored in object store") }); 982 callOnMainThread([protectedThis = WTFMove(protectedThis), this,protectedOperation = WTFMove(protectedOperation), result = WTFMove(result)]() {982 callOnMainThread([protectedThis = WTFMove(protectedThis), protectedOperation = WTFMove(protectedOperation), result = WTFMove(result)]() { 983 983 protectedOperation->completed(result); 984 984 }); -
trunk/Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp
r200361 r201482 93 93 m_havePersistentPermission = canAccess; 94 94 95 callOnMainThread([this, permissionCheckProtector ] {95 callOnMainThread([this, permissionCheckProtector = WTFMove(permissionCheckProtector)] { 96 96 RealtimeMediaSourceCenter::singleton().getMediaStreamTrackSources(this); 97 97 }); … … 161 161 } 162 162 163 RefPtr<MediaDevicesRequest> protectedThis(this); 164 callOnMainThread([protectedThis, devices] { 163 callOnMainThread([protectedThis = Ref<MediaDevicesRequest>(*this), devices = WTFMove(devices)]() mutable { 165 164 protectedThis->m_promise.resolve(devices); 166 165 }); -
trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp
r201420 r201482 96 96 } 97 97 98 void MediaEndpointPeerConnection::runTask( std::function<void()>task)98 void MediaEndpointPeerConnection::runTask(NoncopyableFunction&& task) 99 99 { 100 100 if (m_dtlsFingerprint.isNull()) { 101 101 // Only one task needs to be deferred since it will hold off any others until completed. 102 102 ASSERT(!m_initialDeferredTask); 103 m_initialDeferredTask = task;103 m_initialDeferredTask = WTFMove(task); 104 104 } else 105 callOnMainThread( task);105 callOnMainThread(WTFMove(task)); 106 106 } 107 107 -
trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.h
r198492 r201482 38 38 #include "PeerConnectionBackend.h" 39 39 #include "RTCSessionDescription.h" 40 #include <wtf/NoncopyableFunction.h> 40 41 #include <wtf/RefPtr.h> 41 42 … … 78 79 79 80 private: 80 void runTask( std::function<void()>);81 void runTask(NoncopyableFunction&&); 81 82 void startRunningTasks(); 82 83 … … 92 93 std::unique_ptr<MediaEndpoint> m_mediaEndpoint; 93 94 94 std::function<void()>m_initialDeferredTask;95 NoncopyableFunction m_initialDeferredTask; 95 96 96 97 std::unique_ptr<SDPProcessor> m_sdpProcessor; -
trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
r201080 r201482 136 136 m_videoDeviceUIDs.append(videoTrack->persistentID()); 137 137 138 RefPtr<UserMediaRequest> protectedThis(this); 139 callOnMainThread([protectedThis] { 138 callOnMainThread([protectedThis = Ref<UserMediaRequest>(*this)]() mutable { 140 139 // 2 - The constraints are valid, ask the user for access to media. 141 140 if (UserMediaController* controller = protectedThis->m_controller) 142 controller->requestUserMediaAccess( *protectedThis.get());141 controller->requestUserMediaAccess(protectedThis.get()); 143 142 }); 144 143 } … … 149 148 m_audioDeviceUIDAllowed = audioDeviceUID; 150 149 151 RefPtr<UserMediaRequest> protectedThis(this); 152 callOnMainThread([protectedThis, audioDeviceUID, videoDeviceUID] { 150 callOnMainThread([protectedThis = Ref<UserMediaRequest>(*this), audioDeviceUID, videoDeviceUID]() mutable { 153 151 // 3 - the user granted access, ask platform to create the media stream descriptors. 154 RealtimeMediaSourceCenter::singleton().createMediaStream(protectedThis. get(), audioDeviceUID, videoDeviceUID);152 RealtimeMediaSourceCenter::singleton().createMediaStream(protectedThis.ptr(), audioDeviceUID, videoDeviceUID); 155 153 }); 156 154 } -
trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp
r200895 r201482 798 798 m_isDeletionScheduled = true; 799 799 800 RefPtr<AudioContext> protectedThis(this); 801 callOnMainThread([protectedThis] { 800 callOnMainThread([protectedThis = Ref<AudioContext>(*this)]() mutable { 802 801 protectedThis->deleteMarkedNodes(); 803 802 }); … … 1003 1002 // Make sure to call Document::updateIsPlayingMedia() on the main thread, since 1004 1003 // we could be on the audio I/O thread here and the call into WebCore could block. 1005 RefPtr<AudioContext> protectedThis(this); 1006 callOnMainThread([protectedThis] { 1004 callOnMainThread([protectedThis = Ref<AudioContext>(*this)] { 1007 1005 if (protectedThis->document()) 1008 1006 protectedThis->document()->updateIsPlayingMedia(); -
trunk/Source/WebCore/dom/Document.cpp
r201471 r201482 5387 5387 void Document::postTask(Task task) 5388 5388 { 5389 Task* taskPtr = std::make_unique<Task>(WTFMove(task)).release(); 5390 WeakPtr<Document> documentReference(m_weakFactory.createWeakPtr()); 5391 5392 callOnMainThread([=] { 5389 callOnMainThread([documentReference = m_weakFactory.createWeakPtr(), task = WTFMove(task)]() mutable { 5393 5390 ASSERT(isMainThread()); 5394 std::unique_ptr<Task> task(taskPtr);5395 5391 5396 5392 Document* document = documentReference.get(); … … 5400 5396 Page* page = document->page(); 5401 5397 if ((page && page->defersLoading() && document->activeDOMObjectsAreSuspended()) || !document->m_pendingTasks.isEmpty()) 5402 document->m_pendingTasks.append(WTFMove( *task.release()));5398 document->m_pendingTasks.append(WTFMove(task)); 5403 5399 else 5404 task ->performTask(*document);5400 task.performTask(*document); 5405 5401 }); 5406 5402 } -
trunk/Source/WebCore/dom/ScriptElement.cpp
r200327 r201482 281 281 return true; 282 282 283 RefPtr<Element> element = &m_element; 284 callOnMainThread([this, element] { 283 callOnMainThread([this, element = Ref<Element>(m_element)] { 285 284 dispatchErrorEvent(); 286 285 }); -
trunk/Source/WebCore/fileapi/AsyncFileStream.cpp
r201354 r201482 40 40 #include <wtf/MessageQueue.h> 41 41 #include <wtf/NeverDestroyed.h> 42 #include <wtf/NoncopyableFunction.h> 42 43 43 44 namespace WebCore { … … 64 65 } 65 66 66 static void callOnFileThread( std::function<void()>&& function)67 static void callOnFileThread(NoncopyableFunction&& function) 67 68 { 68 69 ASSERT(isMainThread()); 69 70 ASSERT(function); 70 71 71 static NeverDestroyed<MessageQueue< std::function<void()>>> queue;72 static NeverDestroyed<MessageQueue<NoncopyableFunction>> queue; 72 73 73 74 static std::once_flag createFileThreadOnce; … … 90 91 }); 91 92 92 queue.get().append(std::make_unique< std::function<void()>>(WTFMove(function)));93 queue.get().append(std::make_unique<NoncopyableFunction>(WTFMove(function))); 93 94 } 94 95 … … 103 104 ASSERT(isMainThread()); 104 105 105 // Release so that we can control the timing of deletion below.106 auto& internals = *m_internals.release();107 108 106 // Set flag to prevent client callbacks and also prevent queued operations from starting. 109 internals.destroyed = true;107 m_internals->destroyed = true; 110 108 111 109 // Call through file thread and back to main thread to make sure deletion happens 112 110 // after all file thread functions and all main thread functions called from them. 113 callOnFileThread([&internals] { 114 callOnMainThread([&internals] { 115 delete &internals; 111 callOnFileThread([internals = WTFMove(m_internals)]() mutable { 112 callOnMainThread([internals = WTFMove(internals)] { 116 113 }); 117 114 }); 118 115 } 119 116 120 void AsyncFileStream::perform(std::function<std::function<void(FileStreamClient&)>(FileStream&)> operation)117 void AsyncFileStream::perform(std::function<std::function<void(FileStreamClient&)>(FileStream&)>&& operation) 121 118 { 122 119 auto& internals = *m_internals; 123 callOnFileThread([&internals, operation ] {120 callOnFileThread([&internals, operation = WTFMove(operation)] { 124 121 // Don't do the operation if stop was already called on the main thread. Note that there is 125 122 // a race here, but since skipping the operation is an optimization it's OK that we can't … … 128 125 if (internals.destroyed) 129 126 return; 130 auto mainThreadWork = operation(internals.stream); 131 callOnMainThread([&internals, mainThreadWork] { 127 callOnMainThread([&internals, mainThreadWork = operation(internals.stream)] { 132 128 if (internals.destroyed) 133 129 return; -
trunk/Source/WebCore/fileapi/AsyncFileStream.h
r175782 r201482 57 57 private: 58 58 void start(); 59 void perform(std::function<std::function<void(FileStreamClient&)>(FileStream&)> );59 void perform(std::function<std::function<void(FileStreamClient&)>(FileStream&)>&&); 60 60 61 61 struct Internals; -
trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp
r199708 r201482 118 118 else { 119 119 // BlobRegistryContext performs an isolated copy of data. 120 BlobRegistryContext* context = new BlobRegistryContext(url, path, contentType); 121 callOnMainThread([context] { 122 std::unique_ptr<BlobRegistryContext> blobRegistryContext(context); 123 blobRegistry().registerFileBlobURL(blobRegistryContext->url, BlobDataFileReference::create(blobRegistryContext->path), blobRegistryContext->contentType); 120 callOnMainThread([context = std::make_unique<BlobRegistryContext>(url, path, contentType)] { 121 blobRegistry().registerFileBlobURL(context->url, BlobDataFileReference::create(context->path), context->contentType); 124 122 }); 125 123 } … … 132 130 else { 133 131 // BlobRegistryContext performs an isolated copy of data. 134 BlobRegistryContext* context = new BlobRegistryContext(url, WTFMove(blobParts), contentType); 135 callOnMainThread([context] { 136 std::unique_ptr<BlobRegistryContext> blobRegistryContext(context); 137 blobRegistry().registerBlobURL(blobRegistryContext->url, WTFMove(blobRegistryContext->blobParts), blobRegistryContext->contentType); 132 callOnMainThread([context = std::make_unique<BlobRegistryContext>(url, WTFMove(blobParts), contentType)] { 133 blobRegistry().registerBlobURL(context->url, WTFMove(context->blobParts), context->contentType); 138 134 }); 139 135 } … … 150 146 else { 151 147 // BlobRegistryContext performs an isolated copy of data. 152 BlobRegistryContext* context = new BlobRegistryContext(url, srcURL); 153 callOnMainThread([context] { 154 std::unique_ptr<BlobRegistryContext> blobRegistryContext(context); 155 blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->srcURL); 148 callOnMainThread([context = std::make_unique<BlobRegistryContext>(url, srcURL)] { 149 blobRegistry().registerBlobURL(context->url, context->srcURL); 156 150 }); 157 151 } … … 179 173 else { 180 174 // BlobRegistryContext performs an isolated copy of data. 181 BlobRegistryContext* context = new BlobRegistryContext(newURL, srcURL); 182 callOnMainThread([context, start, end] { 183 std::unique_ptr<BlobRegistryContext> blobRegistryContext(context); 184 blobRegistry().registerBlobURLForSlice(blobRegistryContext->url, blobRegistryContext->srcURL, start, end); 175 callOnMainThread([context = std::make_unique<BlobRegistryContext>(newURL, srcURL), start, end] { 176 blobRegistry().registerBlobURLForSlice(context->url, context->srcURL, start, end); 185 177 }); 186 178 } … … 194 186 else { 195 187 // BlobRegistryContext performs an isolated copy of data. 196 BlobRegistryContext* context = new BlobRegistryContext(url);197 188 BinarySemaphore semaphore; 198 callOnMainThread([context, &semaphore, &resultSize] { 199 std::unique_ptr<BlobRegistryContext> blobRegistryContext(context); 200 resultSize = blobRegistry().blobSize(blobRegistryContext->url); 189 callOnMainThread([context = std::make_unique<BlobRegistryContext>(url), &semaphore, &resultSize] { 190 resultSize = blobRegistry().blobSize(context->url); 201 191 semaphore.signal(); 202 192 }); … … 215 205 else { 216 206 // BlobRegistryContext performs an isolated copy of data. 217 BlobRegistryContext* context = new BlobRegistryContext(url); 218 callOnMainThread([context] { 219 std::unique_ptr<BlobRegistryContext> blobRegistryContext(context); 220 blobRegistry().unregisterBlobURL(blobRegistryContext->url); 207 callOnMainThread([context = std::make_unique<BlobRegistryContext>(url)] { 208 blobRegistry().unregisterBlobURL(context->url); 221 209 }); 222 210 } -
trunk/Source/WebCore/loader/icon/IconDatabase.cpp
r198655 r201482 2091 2091 ++m_mainThreadCallbackCount; 2092 2092 2093 String pageURLCopy = pageURL.isolatedCopy(); 2094 callOnMainThread([this, pageURLCopy] { 2093 callOnMainThread([this, pageURL = pageURL.isolatedCopy()] { 2095 2094 if (m_client) 2096 m_client->didImportIconURLForPageURL(pageURL Copy);2095 m_client->didImportIconURLForPageURL(pageURL); 2097 2096 checkClosedAfterMainThreadCallback(); 2098 2097 }); … … 2104 2103 ++m_mainThreadCallbackCount; 2105 2104 2106 String pageURLCopy = pageURL.isolatedCopy(); 2107 callOnMainThread([this, pageURLCopy] { 2105 callOnMainThread([this, pageURL = pageURL.isolatedCopy()] { 2108 2106 if (m_client) 2109 m_client->didImportIconDataForPageURL(pageURL Copy);2107 m_client->didImportIconDataForPageURL(pageURL); 2110 2108 checkClosedAfterMainThreadCallback(); 2111 2109 }); -
trunk/Source/WebCore/page/ResourceUsageThread.cpp
r195644 r201482 78 78 } 79 79 80 void ResourceUsageThread::notifyObservers(ResourceUsageData& data)80 void ResourceUsageThread::notifyObservers(ResourceUsageData&& data) 81 81 { 82 callOnMainThread([data ]() mutable {82 callOnMainThread([data = WTFMove(data)]() mutable { 83 83 Vector<std::function<void (const ResourceUsageData&)>> functions; 84 84 … … 118 118 ResourceUsageData data; 119 119 platformThreadBody(m_vm, data); 120 notifyObservers( data);120 notifyObservers(WTFMove(data)); 121 121 122 122 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start); -
trunk/Source/WebCore/page/ResourceUsageThread.h
r196780 r201482 57 57 58 58 void waitUntilObservers(); 59 void notifyObservers(ResourceUsageData& );59 void notifyObservers(ResourceUsageData&&); 60 60 61 61 void createThreadIfNeeded(); -
trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp
r200561 r201482 46 46 } 47 47 48 void ScrollingThread::dispatch( std::function<void ()>function)48 void ScrollingThread::dispatch(NoncopyableFunction&& function) 49 49 { 50 50 auto& scrollingThread = ScrollingThread::singleton(); … … 53 53 { 54 54 std::lock_guard<Lock> lock(scrollingThread.m_functionsMutex); 55 scrollingThread.m_functions.append( function);55 scrollingThread.m_functions.append(WTFMove(function)); 56 56 } 57 57 … … 59 59 } 60 60 61 void ScrollingThread::dispatchBarrier( std::function<void ()>function)61 void ScrollingThread::dispatchBarrier(NoncopyableFunction&& function) 62 62 { 63 dispatch([function ]() mutable {63 dispatch([function = WTFMove(function)]() mutable { 64 64 callOnMainThread(WTFMove(function)); 65 65 }); … … 105 105 ASSERT(isCurrentThread()); 106 106 107 Vector< std::function<void ()>> functions;107 Vector<NoncopyableFunction> functions; 108 108 109 109 { -
trunk/Source/WebCore/page/scrolling/ScrollingThread.h
r188642 r201482 34 34 #include <wtf/Lock.h> 35 35 #include <wtf/Noncopyable.h> 36 #include <wtf/NoncopyableFunction.h> 36 37 #include <wtf/Threading.h> 37 38 #include <wtf/Vector.h> … … 48 49 public: 49 50 static bool isCurrentThread(); 50 WEBCORE_EXPORT static void dispatch( std::function<void ()>);51 WEBCORE_EXPORT static void dispatch(NoncopyableFunction&&); 51 52 52 53 // Will dispatch the given function on the main thread once all pending functions 53 54 // on the scrolling thread have finished executing. Used for synchronization purposes. 54 WEBCORE_EXPORT static void dispatchBarrier( std::function<void ()>);55 WEBCORE_EXPORT static void dispatchBarrier(NoncopyableFunction&&); 55 56 56 57 private: … … 80 81 81 82 Lock m_functionsMutex; 82 Vector< std::function<void ()>> m_functions;83 Vector<NoncopyableFunction> m_functions; 83 84 84 85 #if PLATFORM(COCOA) -
trunk/Source/WebCore/page/scrolling/ios/ScrollingTreeIOS.cpp
r194496 r201482 68 68 // we need to release it on the main thread since it has member variables (such as timers) 69 69 // that expect to be destroyed from the main thread. 70 ScrollingCoordinator* scrollingCoordinator = m_scrollingCoordinator.release().leakRef(); 71 callOnMainThread([scrollingCoordinator] { 72 scrollingCoordinator->deref(); 70 callOnMainThread([scrollingCoordinator = WTFMove(m_scrollingCoordinator)] { 73 71 }); 74 72 } … … 87 85 setMainFrameScrollPosition(scrollPosition); 88 86 89 RefPtr<AsyncScrollingCoordinator> scrollingCoordinator = m_scrollingCoordinator; 90 bool localIsHandlingProgrammaticScroll = isHandlingProgrammaticScroll(); 91 92 callOnMainThread([scrollingCoordinator, nodeID, scrollPosition, localIsHandlingProgrammaticScroll, scrollingLayerPositionAction] { 87 callOnMainThread([scrollingCoordinator = m_scrollingCoordinator, nodeID, scrollPosition, localIsHandlingProgrammaticScroll = isHandlingProgrammaticScroll(), scrollingLayerPositionAction] { 93 88 scrollingCoordinator->scheduleUpdateScrollPositionAfterAsyncScroll(nodeID, scrollPosition, localIsHandlingProgrammaticScroll, scrollingLayerPositionAction); 94 89 }); … … 124 119 return; 125 120 126 RefPtr<AsyncScrollingCoordinator> scrollingCoordinator = m_scrollingCoordinator; 127 callOnMainThread([scrollingCoordinator, nodeID, horizontal, vertical] { 121 callOnMainThread([scrollingCoordinator = m_scrollingCoordinator, nodeID, horizontal, vertical] { 128 122 scrollingCoordinator->setActiveScrollSnapIndices(nodeID, horizontal, vertical); 129 123 }); -
trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm
r198078 r201482 76 76 // FIXME: This is a workaround in place for the time being since NSScrollerImps cannot be deallocated 77 77 // on a non-main thread. rdar://problem/24535055 78 NSScrollerImp *retainedVerticalScrollerImp = m_verticalScrollerImp.leakRef(); 79 NSScrollerImp *retainedHorizontalScrollerImp = m_horizontalScrollerImp.leakRef(); 80 WTF::callOnMainThread([retainedVerticalScrollerImp, retainedHorizontalScrollerImp] { 81 [retainedVerticalScrollerImp release]; 82 [retainedHorizontalScrollerImp release]; 78 WTF::callOnMainThread([verticalScrollerImp = WTFMove(m_verticalScrollerImp), horizontalScrollerImp = WTFMove(m_horizontalScrollerImp)] { 83 79 }); 84 80 } -
trunk/Source/WebCore/platform/MemoryPressureHandler.cpp
r201162 r201482 173 173 WorkerThread::releaseFastMallocFreeMemoryInAllThreads(); 174 174 #if ENABLE(ASYNC_SCROLLING) && !PLATFORM(IOS) 175 ScrollingThread::dispatch(WTF::releaseFastMallocFreeMemory); 175 ScrollingThread::dispatch([]() { 176 WTF::releaseFastMallocFreeMemory(); 177 }); 176 178 #endif 177 179 WTF::releaseFastMallocFreeMemory(); -
trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm
r200466 r201482 397 397 398 398 if (!isMainThread()) { 399 auto volumeView = WTFMove(_volumeView); 400 auto routingController = WTFMove(_airPlayPresenceRoutingController); 401 402 callOnMainThread([volumeView, routingController] () mutable { 399 callOnMainThread([volumeView = WTFMove(_volumeView), routingController = WTFMove(_airPlayPresenceRoutingController)] () mutable { 403 400 LOG(Media, "-[WebMediaSessionHelper dealloc] - dipatched to MainThread"); 404 401 … … 436 433 LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes]"); 437 434 438 RetainPtr<WebMediaSessionHelper> strongSelf = self; 439 callOnMainThread([strongSelf] () { 435 callOnMainThread([protectedSelf = RetainPtr<WebMediaSessionHelper>(self)] () { 440 436 LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes] - dipatched to MainThread"); 441 437 442 if ( strongSelf->_airPlayPresenceRoutingController)443 return; 444 445 strongSelf->_airPlayPresenceRoutingController = adoptNS([allocMPAVRoutingControllerInstance() initWithName:@"WebCore - HTML media element checking for AirPlay route presence"]);446 [ strongSelf->_airPlayPresenceRoutingController setDiscoveryMode:MPRouteDiscoveryModePresence];438 if (protectedSelf->_airPlayPresenceRoutingController) 439 return; 440 441 protectedSelf->_airPlayPresenceRoutingController = adoptNS([allocMPAVRoutingControllerInstance() initWithName:@"WebCore - HTML media element checking for AirPlay route presence"]); 442 [protectedSelf->_airPlayPresenceRoutingController setDiscoveryMode:MPRouteDiscoveryModePresence]; 447 443 }); 448 444 } … … 455 451 LOG(Media, "-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]"); 456 452 457 RetainPtr<WebMediaSessionHelper> strongSelf = self; 458 callOnMainThread([strongSelf] () { 453 callOnMainThread([protectedSelf = RetainPtr<WebMediaSessionHelper>(self)] () { 459 454 LOG(Media, "-[WebMediaSessionHelper stopMonitoringAirPlayRoutes] - dipatched to MainThread"); 460 455 461 if (! strongSelf->_airPlayPresenceRoutingController)462 return; 463 464 [ strongSelf->_airPlayPresenceRoutingController setDiscoveryMode:MPRouteDiscoveryModeDisabled];465 strongSelf->_airPlayPresenceRoutingController = nil;456 if (!protectedSelf->_airPlayPresenceRoutingController) 457 return; 458 459 [protectedSelf->_airPlayPresenceRoutingController setDiscoveryMode:MPRouteDiscoveryModeDisabled]; 460 protectedSelf->_airPlayPresenceRoutingController = nil; 466 461 }); 467 462 } -
trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm
r198654 r201482 324 324 m_list->mNumberBuffers = numberOfChannels; 325 325 326 RefPtr<AudioSourceProviderAVFObjC> strongThis = this; 327 callOnMainThread([strongThis, numberOfChannels, sampleRate] { 328 strongThis->m_client->setFormat(numberOfChannels, sampleRate); 326 callOnMainThread([protectedThis = Ref<AudioSourceProviderAVFObjC>(*this), numberOfChannels, sampleRate] { 327 protectedThis->m_client->setFormat(numberOfChannels, sampleRate); 329 328 }); 330 329 } -
trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
r200675 r201482 807 807 m_mainThreadCallPending = true; 808 808 809 auto weakThis = createWeakPtr(); 810 callOnMainThread([weakThis] { 809 callOnMainThread([weakThis = createWeakPtr()] { 811 810 if (!weakThis) 812 811 return; … … 845 844 846 845 if (!m_queuedNotifications.isEmpty() && !m_mainThreadCallPending) { 847 auto weakThis = createWeakPtr(); 848 callOnMainThread([weakThis] { 846 callOnMainThread([weakThis = createWeakPtr()] { 849 847 if (!weakThis) 850 848 return; -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm
r199672 r201482 85 85 if ([[change valueForKey:NSKeyValueChangeNewKey] intValue] == 1) { 86 86 RetainPtr<NSError> error = [NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil]; 87 RetainPtr<WebCDMSessionAVFoundationObjCListener> strongSelf = { self };88 callOnMainThread([ strongSelf, error] {89 if ( strongSelf->_parent)90 strongSelf->_parent->playerDidReceiveError(error.get());87 RetainPtr<WebCDMSessionAVFoundationObjCListener> protectedSelf = { self }; 88 callOnMainThread([protectedSelf = WTFMove(protectedSelf), error = WTFMove(error)] { 89 if (protectedSelf->_parent) 90 protectedSelf->_parent->playerDidReceiveError(error.get()); 91 91 }); 92 92 } -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlaybackTargetPickerMac.mm
r199701 r201482 186 186 return; 187 187 188 RetainPtr<WebAVOutputDeviceMenuControllerHelper> strongSelf = self;189 RetainPtr<NSString> strongKeyPath = keyPath;190 callOnMainThread([ strongSelf, strongKeyPath] {191 MediaPlaybackTargetPickerMac* callback = strongSelf->m_callback;188 RetainPtr<WebAVOutputDeviceMenuControllerHelper> protectedSelf = self; 189 RetainPtr<NSString> protectedKeyPath = keyPath; 190 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedKeyPath = WTFMove(protectedKeyPath)] { 191 MediaPlaybackTargetPickerMac* callback = protectedSelf->m_callback; 192 192 if (!callback) 193 193 return; 194 194 195 if ([ strongKeyPath isEqualToString:externalOutputDeviceAvailableKeyName])195 if ([protectedKeyPath isEqualToString:externalOutputDeviceAvailableKeyName]) 196 196 callback->availableDevicesDidChange(); 197 else if ([ strongKeyPath isEqualToString:externalOutputDevicePickedKeyName])197 else if ([protectedKeyPath isEqualToString:externalOutputDevicePickedKeyName]) 198 198 callback->currentDeviceDidChange(); 199 199 }); -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
r201474 r201482 702 702 return; 703 703 704 auto weakThis = createWeakPtr(); 705 callOnMainThread([this, weakThis] { 704 callOnMainThread([this, weakThis = createWeakPtr()] { 706 705 if (!weakThis) 707 706 return; … … 3442 3441 return; 3443 3442 3444 RetainPtr<WebCoreAVFMovieObserver> strongSelf = self;3445 RetainPtr<NSArray> strongStrings = strings;3446 RetainPtr<NSArray> strongSamples = nativeSamples;3447 callOnMainThread([ strongSelf, strongStrings, strongSamples, itemTime] {3448 MediaPlayerPrivateAVFoundationObjC* callback = strongSelf->m_callback;3443 RetainPtr<WebCoreAVFMovieObserver> protectedSelf = self; 3444 RetainPtr<NSArray> protectedStrings = strings; 3445 RetainPtr<NSArray> protectedNativeSamples = nativeSamples; 3446 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedStrings = WTFMove(protectedStrings), protectedNativeSamples = WTFMove(protectedNativeSamples), itemTime] { 3447 MediaPlayerPrivateAVFoundationObjC* callback = protectedSelf->m_callback; 3449 3448 if (!callback) 3450 3449 return; 3451 3450 MediaTime time = std::max(toMediaTime(itemTime), MediaTime::zeroTime()); 3452 callback->processCue( strongStrings.get(), strongSamples.get(), time);3451 callback->processCue(protectedStrings.get(), protectedNativeSamples.get(), time); 3453 3452 }); 3454 3453 } … … 3461 3460 return; 3462 3461 3463 RetainPtr<WebCoreAVFMovieObserver> strongSelf = self; 3464 callOnMainThread([strongSelf] { 3465 if (MediaPlayerPrivateAVFoundationObjC* callback = strongSelf->m_callback) 3462 callOnMainThread([protectedSelf = RetainPtr<WebCoreAVFMovieObserver>(self)] { 3463 if (MediaPlayerPrivateAVFoundationObjC* callback = protectedSelf->m_callback) 3466 3464 callback->flushCues(); 3467 3465 }); … … 3489 3487 return NO; 3490 3488 3491 RetainPtr<WebCoreAVFLoaderDelegate> strongSelf = self;3492 RetainPtr<AVAssetResourceLoadingRequest> strongRequest = loadingRequest;3493 callOnMainThread([ strongSelf, strongRequest] {3494 MediaPlayerPrivateAVFoundationObjC* callback = strongSelf->m_callback;3489 RetainPtr<WebCoreAVFLoaderDelegate> protectedSelf = self; 3490 RetainPtr<AVAssetResourceLoadingRequest> protectedLoadingRequest = loadingRequest; 3491 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedLoadingRequest = WTFMove(protectedLoadingRequest)] { 3492 MediaPlayerPrivateAVFoundationObjC* callback = protectedSelf->m_callback; 3495 3493 if (!callback) { 3496 [ strongRequest finishLoadingWithError:nil];3494 [protectedLoadingRequest finishLoadingWithError:nil]; 3497 3495 return; 3498 3496 } 3499 3497 3500 if (!callback->shouldWaitForLoadingOfResource( strongRequest.get()))3501 [ strongRequest finishLoadingWithError:nil];3498 if (!callback->shouldWaitForLoadingOfResource(protectedLoadingRequest.get())) 3499 [protectedLoadingRequest finishLoadingWithError:nil]; 3502 3500 }); 3503 3501 … … 3514 3512 return NO; 3515 3513 3516 RetainPtr<WebCoreAVFLoaderDelegate> strongSelf = self;3517 RetainPtr<NSURLAuthenticationChallenge> strongChallenge = challenge;3518 callOnMainThread([ strongSelf, strongChallenge] {3519 MediaPlayerPrivateAVFoundationObjC* callback = strongSelf->m_callback;3514 RetainPtr<WebCoreAVFLoaderDelegate> protectedSelf = self; 3515 RetainPtr<NSURLAuthenticationChallenge> protectedChallenge = challenge; 3516 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedChallenge = WTFMove(protectedChallenge)] { 3517 MediaPlayerPrivateAVFoundationObjC* callback = protectedSelf->m_callback; 3520 3518 if (!callback) { 3521 [[ strongChallenge sender] cancelAuthenticationChallenge:strongChallenge.get()];3519 [[protectedChallenge sender] cancelAuthenticationChallenge:protectedChallenge.get()]; 3522 3520 return; 3523 3521 } 3524 3522 3525 if (!callback->shouldWaitForResponseToAuthenticationChallenge( strongChallenge.get()))3526 [[ strongChallenge sender] cancelAuthenticationChallenge:strongChallenge.get()];3523 if (!callback->shouldWaitForResponseToAuthenticationChallenge(protectedChallenge.get())) 3524 [[protectedChallenge sender] cancelAuthenticationChallenge:protectedChallenge.get()]; 3527 3525 }); 3528 3526 … … 3536 3534 return; 3537 3535 3538 RetainPtr<WebCoreAVFLoaderDelegate> strongSelf = self;3539 RetainPtr<AVAssetResourceLoadingRequest> strongRequest = loadingRequest;3540 callOnMainThread([ strongSelf, strongRequest] {3541 MediaPlayerPrivateAVFoundationObjC* callback = strongSelf->m_callback;3536 RetainPtr<WebCoreAVFLoaderDelegate> protectedSelf = self; 3537 RetainPtr<AVAssetResourceLoadingRequest> protectedLoadingRequest = loadingRequest; 3538 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedLoadingRequest = WTFMove(protectedLoadingRequest)] { 3539 MediaPlayerPrivateAVFoundationObjC* callback = protectedSelf->m_callback; 3542 3540 if (callback) 3543 callback->didCancelLoadingRequest( strongRequest.get());3541 callback->didCancelLoadingRequest(protectedLoadingRequest.get()); 3544 3542 }); 3545 3543 } -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm
r201474 r201482 130 130 { 131 131 MediaPlayerPrivateMediaSourceAVFObjC* player = (MediaPlayerPrivateMediaSourceAVFObjC*)listener; 132 auto weakThis = player->createWeakPtr(); 133 callOnMainThread([weakThis]{ 132 callOnMainThread([weakThis = player->createWeakPtr()] { 134 133 if (!weakThis) 135 134 return; … … 313 312 void MediaPlayerPrivateMediaSourceAVFObjC::play() 314 313 { 315 auto weakThis = createWeakPtr(); 316 callOnMainThread([weakThis]{ 314 callOnMainThread([weakThis = createWeakPtr()] { 317 315 if (!weakThis) 318 316 return; … … 333 331 void MediaPlayerPrivateMediaSourceAVFObjC::pause() 334 332 { 335 auto weakThis = createWeakPtr(); 336 callOnMainThread([weakThis]{ 333 callOnMainThread([weakThis = createWeakPtr()] { 337 334 if (!weakThis) 338 335 return; -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h
r201474 r201482 32 32 #include "MediaStreamPrivate.h" 33 33 #include <wtf/MediaTime.h> 34 #include <wtf/NoncopyableFunction.h> 34 35 #include <wtf/Vector.h> 35 36 #include <wtf/WeakPtr.h> … … 143 144 void renderingModeChanged(); 144 145 145 void scheduleDeferredTask( std::function<void()>);146 void scheduleDeferredTask(NoncopyableFunction&&); 146 147 147 148 enum DisplayMode { -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
r201474 r201482 625 625 } 626 626 627 void MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask( std::function<void()>function)627 void MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask(NoncopyableFunction&& function) 628 628 { 629 629 ASSERT(function); 630 auto weakThis = createWeakPtr(); 631 callOnMainThread([weakThis, function] { 630 callOnMainThread([weakThis = createWeakPtr(), function = WTFMove(function)] { 632 631 if (!weakThis) 633 632 return; -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
r201038 r201482 180 180 #endif 181 181 ASSERT(streamDataParser == _parser); 182 RetainPtr<WebAVStreamDataParserListener> strongSelf = self;183 184 RetainPtr<AVAsset*> strongAsset = asset;185 callOnMainThread([ strongSelf, strongAsset] {186 if ( strongSelf->_parent)187 strongSelf->_parent->didParseStreamDataAsAsset(strongAsset.get());182 RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; 183 184 RetainPtr<AVAsset*> protectedAsset = asset; 185 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedAsset = WTFMove(protectedAsset)] { 186 if (protectedSelf->_parent) 187 protectedSelf->_parent->didParseStreamDataAsAsset(protectedAsset.get()); 188 188 }); 189 189 } … … 196 196 #endif 197 197 ASSERT(streamDataParser == _parser); 198 RetainPtr<WebAVStreamDataParserListener> strongSelf = self;199 200 RetainPtr<AVAsset*> strongAsset = asset;201 callOnMainThread([ strongSelf, strongAsset] {202 if ( strongSelf->_parent)203 strongSelf->_parent->didParseStreamDataAsAsset(strongAsset.get());198 RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; 199 200 RetainPtr<AVAsset*> protectedAsset = asset; 201 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedAsset = WTFMove(protectedAsset)] { 202 if (protectedSelf->_parent) 203 protectedSelf->_parent->didParseStreamDataAsAsset(protectedAsset.get()); 204 204 }); 205 205 } … … 211 211 #endif 212 212 ASSERT(streamDataParser == _parser); 213 RetainPtr<WebAVStreamDataParserListener> strongSelf = self;214 215 RetainPtr<NSError> strongError = error;216 callOnMainThread([ strongSelf, strongError] {217 if ( strongSelf->_parent)218 strongSelf->_parent->didFailToParseStreamDataWithError(strongError.get());213 RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; 214 215 RetainPtr<NSError> protectedError = error; 216 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedError = WTFMove(protectedError)] { 217 if (protectedSelf->_parent) 218 protectedSelf->_parent->didFailToParseStreamDataWithError(protectedError.get()); 219 219 }); 220 220 } … … 226 226 #endif 227 227 ASSERT(streamDataParser == _parser); 228 RetainPtr<WebAVStreamDataParserListener> strongSelf = self;229 230 RetainPtr<CMSampleBufferRef> strongSample = sample;228 RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; 229 230 RetainPtr<CMSampleBufferRef> protectedSample = sample; 231 231 String mediaType = nsMediaType; 232 callOnMainThread([ strongSelf, strongSample, trackID, mediaType, flags] {233 if ( strongSelf->_parent)234 strongSelf->_parent->didProvideMediaDataForTrackID(trackID, strongSample.get(), mediaType, flags);232 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedSample = WTFMove(protectedSample), trackID, mediaType, flags] { 233 if (protectedSelf->_parent) 234 protectedSelf->_parent->didProvideMediaDataForTrackID(trackID, protectedSample.get(), mediaType, flags); 235 235 }); 236 236 } … … 242 242 #endif 243 243 ASSERT(streamDataParser == _parser); 244 RetainPtr<WebAVStreamDataParserListener> strongSelf = self;244 RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; 245 245 246 246 String mediaType = nsMediaType; 247 callOnMainThread([ strongSelf, trackID, mediaType] {248 if ( strongSelf->_parent)249 strongSelf->_parent->didReachEndOfTrackWithTrackID(trackID, mediaType);247 callOnMainThread([protectedSelf = WTFMove(protectedSelf), trackID, mediaType] { 248 if (protectedSelf->_parent) 249 protectedSelf->_parent->didReachEndOfTrackWithTrackID(trackID, mediaType); 250 250 }); 251 251 } … … 273 273 #endif 274 274 ASSERT(streamDataParser == _parser); 275 RetainPtr<WebAVStreamDataParserListener> strongSelf = self; 276 277 RetainPtr<NSData> strongData = initData; 275 RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; 276 278 277 OSObjectPtr<dispatch_semaphore_t> hasSessionSemaphore = adoptOSObject(dispatch_semaphore_create(0)); 279 callOnMainThread([ strongSelf, strongData, trackID, hasSessionSemaphore] {280 if ( strongSelf->_parent)281 strongSelf->_parent->didProvideContentKeyRequestInitializationDataForTrackID(strongData.get(), trackID, hasSessionSemaphore);278 callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedInitData = RetainPtr<NSData>(initData), trackID, hasSessionSemaphore = WTFMove(hasSessionSemaphore)] { 279 if (protectedSelf->_parent) 280 protectedSelf->_parent->didProvideContentKeyRequestInitializationDataForTrackID(protectedInitData.get(), trackID, hasSessionSemaphore); 282 281 }); 283 282 dispatch_semaphore_wait(hasSessionSemaphore.get(), DISPATCH_TIME_FOREVER); … … 383 382 ASSERT(_parent); 384 383 385 RetainPtr<WebAVSampleBufferErrorListener> strongSelf = self;384 RetainPtr<WebAVSampleBufferErrorListener> protectedSelf = self; 386 385 if ([object isKindOfClass:getAVSampleBufferDisplayLayerClass()]) { 387 386 RetainPtr<AVSampleBufferDisplayLayer> layer = (AVSampleBufferDisplayLayer *)object; … … 390 389 if ([keyPath isEqualTo:@"error"]) { 391 390 RetainPtr<NSError> error = [change valueForKey:NSKeyValueChangeNewKey]; 392 callOnMainThread([ strongSelf, layer, error] {393 strongSelf->_parent->layerDidReceiveError(layer.get(), error.get());391 callOnMainThread([protectedSelf = WTFMove(protectedSelf), layer = WTFMove(layer), error = WTFMove(error)] { 392 protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get()); 394 393 }); 395 394 } else if ([keyPath isEqualTo:@"outputObscuredDueToInsufficientExternalProtection"]) { 396 395 if ([[change valueForKey:NSKeyValueChangeNewKey] boolValue]) { 397 396 RetainPtr<NSError> error = [NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil]; 398 callOnMainThread([ strongSelf, layer, error] {399 strongSelf->_parent->layerDidReceiveError(layer.get(), error.get());397 callOnMainThread([protectedSelf = WTFMove(protectedSelf), layer = WTFMove(layer), error = WTFMove(error)] { 398 protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get()); 400 399 }); 401 400 } … … 410 409 ASSERT([keyPath isEqualTo:@"error"]); 411 410 412 callOnMainThread([ strongSelf, renderer, error] {413 strongSelf->_parent->rendererDidReceiveError(renderer.get(), error.get());411 callOnMainThread([protectedSelf = WTFMove(protectedSelf), renderer = WTFMove(renderer), error = WTFMove(error)] { 412 protectedSelf->_parent->rendererDidReceiveError(renderer.get(), error.get()); 414 413 }); 415 414 } else … … 422 421 RetainPtr<NSError> error = [[note userInfo] valueForKey:AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey]; 423 422 424 RetainPtr<WebAVSampleBufferErrorListener> strongSelf = self;425 callOnMainThread([ strongSelf, layer, error] {426 if (! strongSelf->_parent || !strongSelf->_layers.contains(layer.get()))423 RetainPtr<WebAVSampleBufferErrorListener> protectedSelf = self; 424 callOnMainThread([protectedSelf = WTFMove(protectedSelf), layer = WTFMove(layer), error = WTFMove(error)] { 425 if (!protectedSelf->_parent || !protectedSelf->_layers.contains(layer.get())) 427 426 return; 428 strongSelf->_parent->layerDidReceiveError(layer.get(), error.get());427 protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get()); 429 428 }); 430 429 } -
trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
r200967 r201482 296 296 static void patternReleaseCallback(void* info) 297 297 { 298 auto image = static_cast<CGImageRef>(info); 299 callOnMainThread([image] { 298 callOnMainThread([image = static_cast<CGImageRef>(info)] { 300 299 CGImageRelease(image); 301 300 }); -
trunk/Source/WebCore/platform/graphics/cg/PatternCG.cpp
r188772 r201482 57 57 static void patternReleaseCallback(void* info) 58 58 { 59 auto image = static_cast<CGImageRef>(info); 60 61 callOnMainThread([image] { 59 callOnMainThread([image = static_cast<CGImageRef>(info)] { 62 60 CGImageRelease(image); 63 61 }); -
trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp
r199114 r201482 487 487 m_loadingProgress = SUCCEEDED(hr); 488 488 489 auto weakPtr = m_weakPtrFactory.createWeakPtr(); 490 callOnMainThread([weakPtr] { 489 callOnMainThread([weakPtr = m_weakPtrFactory.createWeakPtr()] { 491 490 if (!weakPtr) 492 491 return; … … 517 516 switch (mediaEventType) { 518 517 case MESessionTopologySet: { 519 auto weakPtr = m_weakPtrFactory.createWeakPtr(); 520 callOnMainThread([weakPtr] { 518 callOnMainThread([weakPtr = m_weakPtrFactory.createWeakPtr()] { 521 519 if (!weakPtr) 522 520 return; … … 527 525 528 526 case MEBufferingStarted: { 529 auto weakPtr = m_weakPtrFactory.createWeakPtr(); 530 callOnMainThread([weakPtr] { 527 callOnMainThread([weakPtr = m_weakPtrFactory.createWeakPtr()] { 531 528 if (!weakPtr) 532 529 return; … … 537 534 538 535 case MEBufferingStopped: { 539 auto weakPtr = m_weakPtrFactory.createWeakPtr(); 540 callOnMainThread([weakPtr] { 536 callOnMainThread([weakPtr = m_weakPtrFactory.createWeakPtr()] { 541 537 if (!weakPtr) 542 538 return; … … 547 543 548 544 case MESessionEnded: { 549 auto weakPtr = m_weakPtrFactory.createWeakPtr(); 550 callOnMainThread([weakPtr] { 545 callOnMainThread([weakPtr = m_weakPtrFactory.createWeakPtr()] { 551 546 if (!weakPtr) 552 547 return; … … 1676 1671 // Invalidate the video area 1677 1672 if (m_mediaPlayer) { 1678 auto weakPtr = m_mediaPlayer->m_weakPtrFactory.createWeakPtr(); 1679 callOnMainThread([weakPtr] { 1673 callOnMainThread([weakPtr = m_mediaPlayer->m_weakPtrFactory.createWeakPtr()] { 1680 1674 if (weakPtr) 1681 1675 weakPtr->invalidateFrameView(); -
trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp
r197929 r201482 300 300 } 301 301 302 void MediaStreamPrivate::scheduleDeferredTask( std::function<void()>function)302 void MediaStreamPrivate::scheduleDeferredTask(NoncopyableFunction&& function) 303 303 { 304 304 ASSERT(function); 305 auto weakThis = createWeakPtr(); 306 callOnMainThread([weakThis, function] { 305 callOnMainThread([weakThis = createWeakPtr(), function = WTFMove(function)] { 307 306 if (!weakThis) 308 307 return; -
trunk/Source/WebCore/platform/mediastream/MediaStreamPrivate.h
r197929 r201482 42 42 #include <wtf/HashMap.h> 43 43 #include <wtf/MediaTime.h> 44 #include <wtf/NoncopyableFunction.h> 44 45 #include <wtf/RefCounted.h> 45 46 #include <wtf/RefPtr.h> … … 112 113 void updateActiveVideoTrack(); 113 114 114 void scheduleDeferredTask( std::function<void()>);115 void scheduleDeferredTask(NoncopyableFunction&&); 115 116 116 117 WeakPtrFactory<MediaStreamPrivate> m_weakPtrFactory; -
trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h
r192954 r201482 32 32 #include "RealtimeMediaSource.h" 33 33 #include "Timer.h" 34 #include <wtf/NoncopyableFunction.h> 34 35 #include <wtf/RetainPtr.h> 35 36 #include <wtf/WeakPtr.h> … … 86 87 void setAudioSampleBufferDelegate(AVCaptureAudioDataOutput*); 87 88 88 void scheduleDeferredTask( std::function<void ()>);89 void scheduleDeferredTask(NoncopyableFunction&&); 89 90 90 91 private: -
trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm
r197929 r201482 241 241 } 242 242 243 void AVMediaCaptureSource::scheduleDeferredTask( std::function<void ()>function)243 void AVMediaCaptureSource::scheduleDeferredTask(NoncopyableFunction&& function) 244 244 { 245 245 ASSERT(function); 246 247 auto weakThis = createWeakPtr(); 248 callOnMainThread([weakThis, function] { 246 callOnMainThread([weakThis = createWeakPtr(), function = WTFMove(function)] { 249 247 if (!weakThis) 250 248 return; -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp
r197114 r201482 164 164 { 165 165 RefPtr<MediaStreamTrackSourcesRequestClient> requestClient = prpClient; 166 167 166 TrackSourceInfoVector sources = AVCaptureDeviceManager::singleton().getSourcesInfo(requestClient->requestOrigin()); 168 167 169 callOnMainThread([this, requestClient , sources] {168 callOnMainThread([this, requestClient = WTFMove(requestClient), sources = WTFMove(sources)] { 170 169 requestClient->didCompleteTrackSourceInfoRequest(sources); 171 170 }); -
trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm
r193389 r201482 215 215 m_list->mNumberBuffers = numberOfChannels; 216 216 217 RefPtr<WebAudioSourceProviderAVFObjC> strongThis = this;218 callOnMainThread([ strongThis, numberOfChannels, sampleRate] {219 if ( strongThis->m_client)220 strongThis->m_client->setFormat(numberOfChannels, sampleRate);217 RefPtr<WebAudioSourceProviderAVFObjC> protectedThis = this; 218 callOnMainThread([protectedThis = WTFMove(protectedThis), numberOfChannels, sampleRate] { 219 if (protectedThis->m_client) 220 protectedThis->m_client->setFormat(numberOfChannels, sampleRate); 221 221 }); 222 222 } -
trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
r197114 r201482 160 160 sources.append(MockRealtimeMediaSource::trackSourceWithUID(MockRealtimeMediaSource::mockVideoSourcePersistentID(), nullptr)); 161 161 162 callOnMainThread([this, requestClient , sources] {162 callOnMainThread([this, requestClient = WTFMove(requestClient), sources = WTFMove(sources)] { 163 163 requestClient->didCompleteTrackSourceInfoRequest(sources); 164 164 }); -
trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp
r200895 r201482 188 188 } 189 189 190 RefPtr<BlobResourceHandle> protectedThis(this);191 192 190 // Finish this async call quickly and return. 193 callOnMainThread([protectedThis ]{191 callOnMainThread([protectedThis = Ref<BlobResourceHandle>(*this)]() mutable { 194 192 protectedThis->doStart(); 195 193 }); … … 666 664 // Schedule to notify the client from a standalone function because the client might dispose the handle immediately from the callback function 667 665 // while we still have BlobResourceHandle calls in the stack. 668 RefPtr<BlobResourceHandle> protectedThis(this); 669 callOnMainThread([protectedThis] { 670 doNotifyFinish(*protectedThis); 666 callOnMainThread([protectedThis = Ref<BlobResourceHandle>(*this)]() mutable { 667 doNotifyFinish(protectedThis); 671 668 }); 672 669 -
trunk/Source/WebCore/platform/network/DataURLDecoder.cpp
r199735 r201482 169 169 } 170 170 171 void decode(const URL& url, const ScheduleContext& scheduleContext, DecodeCompletionHandler completionHandler)171 void decode(const URL& url, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler) 172 172 { 173 173 ASSERT(url.protocolIsData()); 174 174 175 175 auto decodeTask = createDecodeTask(url, scheduleContext, WTFMove(completionHandler)); 176 auto* decodeTaskPtr = decodeTask.release(); 177 decodeQueue().dispatch([decodeTaskPtr] { 178 auto& decodeTask = *decodeTaskPtr; 179 180 if (decodeTask.isBase64) 181 decodeBase64(decodeTask); 176 decodeQueue().dispatch([decodeTask = WTFMove(decodeTask)]() mutable { 177 if (decodeTask->isBase64) 178 decodeBase64(*decodeTask); 182 179 else 183 decodeEscaped( decodeTask);180 decodeEscaped(*decodeTask); 184 181 185 182 #if HAVE(RUNLOOP_TIMER) 186 DecodingResultDispatcher::dispatch( std::unique_ptr<DecodeTask>(decodeTaskPtr));183 DecodingResultDispatcher::dispatch(WTFMove(decodeTask)); 187 184 #else 188 callOnMainThread([decodeTaskPtr] { 189 std::unique_ptr<DecodeTask> decodeTask(decodeTaskPtr); 185 callOnMainThread([decodeTask = WTFMove(decodeTask)] { 190 186 if (!decodeTask->result.data) { 191 187 decodeTask->completionHandler({ }); -
trunk/Source/WebCore/platform/network/DataURLDecoder.h
r191673 r201482 56 56 }; 57 57 58 void decode(const URL&, const ScheduleContext&, DecodeCompletionHandler );58 void decode(const URL&, const ScheduleContext&, DecodeCompletionHandler&&); 59 59 60 60 } -
trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm
r200578 r201482 93 93 task.get().session = nil; 94 94 95 // FIXME(C++14): When we can move RefPtrs directly into blocks, replace this with a RefPtr&&: 96 WebCore::PlatformMediaResourceLoader* loader = _loader.leakRef(); 97 callOnMainThread([loader] { 98 loader->deref(); 95 callOnMainThread([loader = WTFMove(_loader)] { 99 96 }); 100 97 [super dealloc]; … … 467 464 { 468 465 self.state = NSURLSessionTaskStateCanceling; 469 RetainPtr<WebCoreNSURLSessionDataTask> strongSelf { self }; 470 callOnMainThread([strongSelf] { 471 [strongSelf _cancel]; 472 [strongSelf _finish]; 466 callOnMainThread([protectedSelf = RetainPtr<WebCoreNSURLSessionDataTask>(self)] { 467 [protectedSelf _cancel]; 468 [protectedSelf _finish]; 473 469 }); 474 470 } … … 476 472 - (void)suspend 477 473 { 478 RetainPtr<WebCoreNSURLSessionDataTask> strongSelf { self }; 479 callOnMainThread([strongSelf] { 474 callOnMainThread([protectedSelf = RetainPtr<WebCoreNSURLSessionDataTask>(self)] { 480 475 // NSURLSessionDataTasks must start over after suspending, so while 481 476 // we could defer loading at this point, instead cancel and restart 482 477 // upon resume so as to adhere to NSURLSessionDataTask semantics. 483 [ strongSelf _cancel];484 strongSelf.get().state = NSURLSessionTaskStateSuspended;478 [protectedSelf _cancel]; 479 protectedSelf.get().state = NSURLSessionTaskStateSuspended; 485 480 }); 486 481 } … … 488 483 - (void)resume 489 484 { 490 RetainPtr<WebCoreNSURLSessionDataTask> strongSelf { self }; 491 callOnMainThread([strongSelf] { 492 if (strongSelf.get().state != NSURLSessionTaskStateSuspended) 485 callOnMainThread([protectedSelf = RetainPtr<WebCoreNSURLSessionDataTask>(self)] { 486 if (protectedSelf.get().state != NSURLSessionTaskStateSuspended) 493 487 return; 494 488 495 [ strongSelf _restart];496 strongSelf.get().state = NSURLSessionTaskStateRunning;489 [protectedSelf _restart]; 490 protectedSelf.get().state = NSURLSessionTaskStateRunning; 497 491 }); 498 492 } -
trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp
r201354 r201482 403 403 404 404 if (httpCode >= 200 && httpCode < 300) { 405 URLCapture capturedUrl(getCurlEffectiveURL(m_curlHandle)); 406 RefPtr<CurlDownload> protectedThis(this); 407 408 callOnMainThread([this, capturedUrl, protectedThis] { 409 m_response.setURL(capturedUrl.url()); 405 URL url = getCurlEffectiveURL(m_curlHandle); 406 callOnMainThread([this, url = url.isolatedCopy(), protectedThis = Ref<CurlDownload>(*this)] { 407 m_response.setURL(url); 410 408 m_response.setMimeType(extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPHeaderName::ContentType))); 411 409 m_response.setTextEncodingName(extractCharsetFromMediaType(m_response.httpHeaderField(HTTPHeaderName::ContentType))); … … 415 413 } 416 414 } else { 417 StringCapture capturedHeader(header); 418 419 RefPtr<CurlDownload> protectedThis(this); 420 421 callOnMainThread([this, capturedHeader, protectedThis] { 422 int splitPos = capturedHeader.string().find(":"); 415 callOnMainThread([this, header = header.isolatedCopy(), protectedThis = Ref<CurlDownload>(*this)] { 416 int splitPos = header.string().find(":"); 423 417 if (splitPos != -1) 424 m_response.setHTTPHeaderField( capturedHeader.string().left(splitPos), capturedHeader.string().substring(splitPos + 1).stripWhiteSpace());418 m_response.setHTTPHeaderField(header.string().left(splitPos), header.string().substring(splitPos + 1).stripWhiteSpace()); 425 419 }); 426 420 } -
trunk/Source/WebKit/ChangeLog
r201398 r201482 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 callOnMainThread() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158166 5 6 Reviewed by Brady Eidson. 7 8 callOnMainThread() should not copy captured lambda variables. This 9 function is usually called cross-thread with a lambda and copying 10 the lambda (and its captured variables) can lead to thread-safety 11 issues. 12 13 This patch updates callOnMainThread() to take a NoncopyableFunction&& 14 in parameter instead of a std::function. The call sites of 15 callOnMainThread() have also been updated to use C++14's lambda 16 capture with initializer. 17 18 * Storage/StorageAreaSync.cpp: 19 (WebCore::StorageAreaSync::deleteEmptyDatabase): 20 * Storage/StorageSyncManager.cpp: 21 (WebCore::StorageSyncManager::dispatch): 22 * Storage/StorageSyncManager.h: 23 * Storage/StorageThread.cpp: 24 (WebCore::StorageThread::dispatch): 25 (WebCore::StorageThread::terminate): 26 (WebCore::StorageThread::releaseFastMallocFreeMemoryInAllThreads): 27 * Storage/StorageThread.h: 28 * Storage/StorageTracker.cpp: 29 (WebCore::StorageTracker::syncFileSystemAndTrackerDatabase): 30 (WebCore::StorageTracker::setOriginDetails): 31 1 32 2016-05-25 Alex Christensen <achristensen@webkit.org> 2 33 -
trunk/Source/WebKit/Storage/StorageAreaSync.cpp
r188594 r201482 515 515 m_database.close(); 516 516 if (StorageTracker::tracker().isActive()) { 517 StringImpl* databaseIdentifierCopy = &m_databaseIdentifier.impl()->isolatedCopy().leakRef(); 518 callOnMainThread([databaseIdentifierCopy] { 519 StorageTracker::tracker().deleteOriginWithIdentifier(databaseIdentifierCopy); 520 databaseIdentifierCopy->deref(); 517 callOnMainThread([databaseIdentifier = m_databaseIdentifier.isolatedCopy()] { 518 StorageTracker::tracker().deleteOriginWithIdentifier(databaseIdentifier); 521 519 }); 522 520 } else { -
trunk/Source/WebKit/Storage/StorageSyncManager.cpp
r177813 r201482 64 64 } 65 65 66 void StorageSyncManager::dispatch( const std::function<void ()>& function)66 void StorageSyncManager::dispatch(NoncopyableFunction&& function) 67 67 { 68 68 ASSERT(isMainThread()); … … 70 70 71 71 if (m_thread) 72 m_thread->dispatch( function);72 m_thread->dispatch(WTFMove(function)); 73 73 } 74 74 -
trunk/Source/WebKit/Storage/StorageSyncManager.h
r177813 r201482 29 29 #include <functional> 30 30 #include <wtf/Forward.h> 31 #include <wtf/NoncopyableFunction.h> 31 32 #include <wtf/PassRefPtr.h> 32 33 #include <wtf/RefCounted.h> … … 43 44 ~StorageSyncManager(); 44 45 45 void dispatch( const std::function<void ()>&);46 void dispatch(NoncopyableFunction&&); 46 47 void close(); 47 48 -
trunk/Source/WebKit/Storage/StorageThread.cpp
r194987 r201482 75 75 } 76 76 77 void StorageThread::dispatch( const std::function<void ()>& function)77 void StorageThread::dispatch(NoncopyableFunction&& function) 78 78 { 79 79 ASSERT(isMainThread()); 80 80 ASSERT(!m_queue.killed() && m_threadID); 81 m_queue.append(std::make_unique< std::function<void ()>>(function));81 m_queue.append(std::make_unique<NoncopyableFunction>(WTFMove(function))); 82 82 } 83 83 … … 91 91 return; 92 92 93 m_queue.append(std::make_unique< std::function<void ()>>([this] {93 m_queue.append(std::make_unique<NoncopyableFunction>([this] { 94 94 performTerminate(); 95 95 })); … … 109 109 HashSet<StorageThread*>& threads = activeStorageThreads(); 110 110 111 for (HashSet<StorageThread*>::iterator it = threads.begin(), end = threads.end(); it != end; ++it) 112 (*it)->dispatch(WTF::releaseFastMallocFreeMemory); 111 for (HashSet<StorageThread*>::iterator it = threads.begin(), end = threads.end(); it != end; ++it) { 112 (*it)->dispatch([]() { 113 WTF::releaseFastMallocFreeMemory(); 114 }); 115 } 113 116 } 114 117 -
trunk/Source/WebKit/Storage/StorageThread.h
r177813 r201482 30 30 #include <wtf/HashSet.h> 31 31 #include <wtf/MessageQueue.h> 32 #include <wtf/ PassRefPtr.h>32 #include <wtf/NoncopyableFunction.h> 33 33 #include <wtf/Threading.h> 34 34 … … 47 47 void terminate(); 48 48 49 void dispatch( const std::function<void()>&);49 void dispatch(NoncopyableFunction&&); 50 50 51 51 static void releaseFastMallocFreeMemoryInAllThreads(); … … 60 60 61 61 ThreadIdentifier m_threadID; 62 MessageQueue< std::function<void()>> m_queue;62 MessageQueue<NoncopyableFunction> m_queue; 63 63 }; 64 64 -
trunk/Source/WebKit/Storage/StorageTracker.cpp
r195452 r201482 294 294 continue; 295 295 296 String originIdentifierCopy = originIdentifier.isolatedCopy(); 297 callOnMainThread([this, originIdentifierCopy] { 298 deleteOriginWithIdentifier(originIdentifierCopy); 296 callOnMainThread([this, originIdentifier = originIdentifier.isolatedCopy()] { 297 deleteOriginWithIdentifier(originIdentifier); 299 298 }); 300 299 } … … 315 314 } 316 315 317 String originIdentifierCopy = originIdentifier.isolatedCopy(); 318 String databaseFileCopy = databaseFile.isolatedCopy(); 319 auto function = [this, originIdentifierCopy, databaseFileCopy] { 320 syncSetOriginDetails(originIdentifierCopy, databaseFileCopy); 316 auto function = [this, originIdentifier = originIdentifier.isolatedCopy(), databaseFile = databaseFile.isolatedCopy()] { 317 syncSetOriginDetails(originIdentifier, databaseFile); 321 318 }; 322 319 323 320 if (isMainThread()) { 324 321 ASSERT(m_thread); 325 m_thread->dispatch( function);322 m_thread->dispatch(WTFMove(function)); 326 323 } else { 327 324 // FIXME: This weird ping-ponging was done to fix a deadlock. We should figure out a cleaner way to avoid it instead. 328 callOnMainThread([this, function ]{329 m_thread->dispatch( function);325 callOnMainThread([this, function = WTFMove(function)]() mutable { 326 m_thread->dispatch(WTFMove(function)); 330 327 }); 331 328 } -
trunk/Source/WebKit/mac/ChangeLog
r201481 r201482 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 callOnMainThread() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158166 5 6 Reviewed by Brady Eidson. 7 8 callOnMainThread() should not copy captured lambda variables. This 9 function is usually called cross-thread with a lambda and copying 10 the lambda (and its captured variables) can lead to thread-safety 11 issues. 12 13 This patch updates callOnMainThread() to take a NoncopyableFunction&& 14 in parameter instead of a std::function. The call sites of 15 callOnMainThread() have also been updated to use C++14's lambda 16 capture with initializer. 17 18 * Storage/WebDatabaseManagerClient.mm: 19 (DidModifyOriginData::dispatchToMainThread): 20 (DidModifyOriginData::DidModifyOriginData): Deleted. 21 * Storage/WebStorageTrackerClient.mm: 22 (WebStorageTrackerClient::dispatchDidModifyOrigin): 23 1 24 2016-05-27 Caitlin Potter <caitp@igalia.com> 2 25 -
trunk/Source/WebKit/mac/Storage/WebDatabaseManagerClient.mm
r188772 r201482 104 104 static void dispatchToMainThread(WebDatabaseManagerClient* client, SecurityOrigin* origin) 105 105 { 106 DidModifyOriginData* context = new DidModifyOriginData(client, origin->isolatedCopy());107 callOnMainThread([context ] {106 auto context = std::make_unique<DidModifyOriginData>(client, origin->isolatedCopy()); 107 callOnMainThread([context = WTFMove(context)] { 108 108 context->client->dispatchDidModifyOrigin(context->origin.get()); 109 delete context;110 109 }); 111 110 } 112 111 113 private:114 112 DidModifyOriginData(WebDatabaseManagerClient* client, PassRefPtr<SecurityOrigin> origin) 115 113 : client(client) … … 118 116 } 119 117 118 private: 120 119 WebDatabaseManagerClient* client; 121 120 RefPtr<SecurityOrigin> origin; -
trunk/Source/WebKit/mac/Storage/WebStorageTrackerClient.mm
r188772 r201482 59 59 void WebStorageTrackerClient::dispatchDidModifyOrigin(const String& originIdentifier) 60 60 { 61 RefPtr<SecurityOrigin>origin = SecurityOrigin::createFromDatabaseIdentifier(originIdentifier);61 auto origin = SecurityOrigin::createFromDatabaseIdentifier(originIdentifier); 62 62 63 63 if (isMainThread()) { 64 dispatchDidModifyOrigin( origin);64 dispatchDidModifyOrigin(WTFMove(origin)); 65 65 return; 66 66 } 67 67 68 callOnMainThread([origin ]{69 WebStorageTrackerClient::sharedWebStorageTrackerClient()->dispatchDidModifyOrigin( origin.get());68 callOnMainThread([origin = WTFMove(origin)]() mutable { 69 WebStorageTrackerClient::sharedWebStorageTrackerClient()->dispatchDidModifyOrigin(WTFMove(origin)); 70 70 }); 71 71 }
Note:
See TracChangeset
for help on using the changeset viewer.