WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
158166
callOnMainThread() should not copy captured lambda variables
https://bugs.webkit.org/show_bug.cgi?id=158166
Summary
callOnMainThread() should not copy captured lambda variables
Chris Dumez
Reported
2016-05-27 14:24:28 PDT
callOnMainThread() should not copy captured lambda variables to reduce the risk of thread-related races.
Attachments
WIP patch
(77.80 KB, patch)
2016-05-27 16:53 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(98.91 KB, patch)
2016-05-27 18:27 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(98.91 KB, patch)
2016-05-27 19:01 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(98.92 KB, patch)
2016-05-27 19:27 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(108.15 KB, patch)
2016-05-27 21:42 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(108.06 KB, patch)
2016-05-27 22:12 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(5)
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2016-05-27 16:53:21 PDT
Created
attachment 280012
[details]
WIP patch
WebKit Commit Bot
Comment 2
2016-05-27 16:55:53 PDT
Attachment 280012
[details]
did not pass style-queue: ERROR: Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:132: Missing space before { [whitespace/braces] [5] ERROR: Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:314: Missing space before { [whitespace/braces] [5] ERROR: Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:333: Missing space before { [whitespace/braces] [5] Total errors found: 3 in 54 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 3
2016-05-27 18:27:54 PDT
Created
attachment 280015
[details]
Patch
WebKit Commit Bot
Comment 4
2016-05-27 18:29:14 PDT
Attachment 280015
[details]
did not pass style-queue: ERROR: Source/WebCore/platform/MemoryPressureHandler.cpp:175: More than one command on the same line [whitespace/newline] [4] ERROR: Source/WebKit/Storage/StorageThread.cpp:112: More than one command on the same line [whitespace/newline] [4] Total errors found: 2 in 61 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 5
2016-05-27 19:01:50 PDT
Created
attachment 280016
[details]
Patch
WebKit Commit Bot
Comment 6
2016-05-27 19:02:37 PDT
Attachment 280016
[details]
did not pass style-queue: ERROR: Source/WebCore/platform/MemoryPressureHandler.cpp:175: More than one command on the same line [whitespace/newline] [4] ERROR: Source/WebKit/Storage/StorageThread.cpp:112: More than one command on the same line [whitespace/newline] [4] Total errors found: 2 in 61 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 7
2016-05-27 19:27:26 PDT
Created
attachment 280017
[details]
Patch
WebKit Commit Bot
Comment 8
2016-05-27 19:29:38 PDT
Attachment 280017
[details]
did not pass style-queue: ERROR: Source/WebCore/platform/MemoryPressureHandler.cpp:175: More than one command on the same line [whitespace/newline] [4] ERROR: Source/WebKit/Storage/StorageThread.cpp:112: More than one command on the same line [whitespace/newline] [4] Total errors found: 2 in 61 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 9
2016-05-27 20:01:07 PDT
Patch is ready for review. It is building everywhere and passing the tests.
Brady Eidson
Comment 10
2016-05-27 20:49:07 PDT
Comment on
attachment 280017
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=280017&action=review
This is so great. r-, but the changes are just mechanical replacements. This patch makes it clear to me I'll need to try to update the style checker rules for lambda captures :) Imagine the style checker caught all these protectors - Now would be a great time to update them! :)
> Source/WTF/wtf/FunctionDispatcher.h:30 > +#include <wtf/Functional.h>
Should we call the new header NoncopyableFunction.h, as that is its only contents?
> Source/WebCore/platform/MemoryPressureHandler.cpp:175 > + ScrollingThread::dispatch([]() { WTF::releaseFastMallocFreeMemory(); });
Please put this on two lines - I don't think there should ever be an exception for any lambda, no matter how simple it is, as it is important for them to stand out at a glance.
> Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm:435 > + callOnMainThread([strongSelf = RetainPtr<WebMediaSessionHelper>(self)] () {
protectedSelf (Here, and everywhere else where we touch a "strongSelf")
> Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:326 > + callOnMainThread([strongThis = Ref<AudioSourceProviderAVFObjC>(*this), numberOfChannels, sampleRate] {
protectedThis (here, and everywhere else we touch a "strongThis")
> Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:279 > + callOnMainThread([strongSelf = WTFMove(strongSelf), strongData = WTFMove(strongData), trackID, hasSessionSemaphore = WTFMove(hasSessionSemaphore)] {
protectedInitData
> Source/WebKit/Storage/StorageThread.cpp:112 > + (*it)->dispatch([]() { WTF::releaseFastMallocFreeMemory(); });
Please put this on two lines - I don't think there should ever be an exception for any lambda, no matter how simple it is, as it is important for them to stand out at a glance.
Chris Dumez
Comment 11
2016-05-27 21:42:06 PDT
Created
attachment 280019
[details]
Patch
Brady Eidson
Comment 12
2016-05-27 22:02:50 PDT
MockSourceBufferPrivate - exit_code: 65 huh.
Brady Eidson
Comment 13
2016-05-27 22:06:17 PDT
Comment on
attachment 280019
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=280019&action=review
r+ (with one nit) assuming you get the build working.
> Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:279 > - RetainPtr<WebAVStreamDataParserListener> strongSelf = self; > + RetainPtr<WebAVStreamDataParserListener> protectedSelf = self; > > - RetainPtr<NSData> strongData = initData; > + RetainPtr<NSData> protectedInitData = initData; > OSObjectPtr<dispatch_semaphore_t> hasSessionSemaphore = adoptOSObject(dispatch_semaphore_create(0)); > - callOnMainThread([strongSelf, strongData, trackID, hasSessionSemaphore] { > - if (strongSelf->_parent) > - strongSelf->_parent->didProvideContentKeyRequestInitializationDataForTrackID(strongData.get(), trackID, hasSessionSemaphore); > + callOnMainThread([protectedSelf = WTFMove(protectedSelf), protectedInitData = WTFMove(protectedInitData), trackID, hasSessionSemaphore = WTFMove(hasSessionSemaphore)] {
If you have to take another pass to get the builds working, you can initialize the two RetainPtrs here inside the lambda capture instead of having the local variables.
Chris Dumez
Comment 14
2016-05-27 22:12:10 PDT
Created
attachment 280021
[details]
Patch
Chris Dumez
Comment 15
2016-05-27 22:50:32 PDT
Comment on
attachment 280021
[details]
Patch Clearing flags on attachment: 280021 Committed
r201482
: <
http://trac.webkit.org/changeset/201482
>
Chris Dumez
Comment 16
2016-05-27 22:50:37 PDT
All reviewed patches have been landed. Closing bug.
Csaba Osztrogonác
Comment 17
2016-05-30 02:17:09 PDT
(In reply to
comment #15
)
> Comment on
attachment 280021
[details]
> Patch > > Clearing flags on attachment: 280021 > > Committed
r201482
: <
http://trac.webkit.org/changeset/201482
>
It broke the WinCairo (curl) build, see build.webkit.org for details. (cc-ing port maintainers)
Alex Christensen
Comment 18
2016-05-31 10:52:53 PDT
http://trac.webkit.org/changeset/201515
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug