RESOLVED FIXED 225935
Use WTF::Locker for locking BaseAudioContext's graph lock
https://bugs.webkit.org/show_bug.cgi?id=225935
Summary Use WTF::Locker for locking BaseAudioContext's graph lock
Chris Dumez
Reported 2021-05-18 13:28:31 PDT
Use WTF::Locker for locking BaseAudioContext's graph lock instead of our own AutoLocker.
Attachments
Patch (30.44 KB, patch)
2021-05-18 15:12 PDT, Chris Dumez
no flags
Patch (29.08 KB, patch)
2021-05-18 16:38 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2021-05-18 15:12:32 PDT
Sam Weinig
Comment 2 2021-05-18 15:30:33 PDT
Comment on attachment 428986 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=428986&action=review > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > + auto contextLocker = holdLock(context().graphLock()); I believe we are trying to move away from holdLock() and just use: Locker locker { context().graphLock() }; because holdLock does not play nice with ThreadSafetyAnalysis. We really should just do a global replace of holdLock() to get this over with.
Chris Dumez
Comment 3 2021-05-18 15:32:36 PDT
(In reply to Sam Weinig from comment #2) > Comment on attachment 428986 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > + auto contextLocker = holdLock(context().graphLock()); > > I believe we are trying to move away from holdLock() and just use: > > Locker locker { context().graphLock() }; > > because holdLock does not play nice with ThreadSafetyAnalysis. > > We really should just do a global replace of holdLock() to get this over > with. holdLock() looks nicer and there is no harm in using it here since we're not using a Lock type that supports static analysis. My understanding was that we just can use holdLock() with StaticLock but it was OK to use holdLock() for other types of locks?
Chris Dumez
Comment 4 2021-05-18 15:34:25 PDT
(In reply to Chris Dumez from comment #3) > (In reply to Sam Weinig from comment #2) > > Comment on attachment 428986 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > + auto contextLocker = holdLock(context().graphLock()); > > > > I believe we are trying to move away from holdLock() and just use: > > > > Locker locker { context().graphLock() }; > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > We really should just do a global replace of holdLock() to get this over > > with. > > holdLock() looks nicer and there is no harm in using it here since we're not > using a Lock type that supports static analysis. My understanding was that > we just can use holdLock() with StaticLock but it was OK to use holdLock() > for other types of locks? Also note that it wouldn't be: Locker locker { context().graphLock() }; It would be: Locker<RecursiveLock> locker { context().graphLock() }; Which would look even worse. I much prefer using auto that having to name the lock type.
Sam Weinig
Comment 5 2021-05-18 15:53:07 PDT
(In reply to Chris Dumez from comment #3) > (In reply to Sam Weinig from comment #2) > > Comment on attachment 428986 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > + auto contextLocker = holdLock(context().graphLock()); > > > > I believe we are trying to move away from holdLock() and just use: > > > > Locker locker { context().graphLock() }; > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > We really should just do a global replace of holdLock() to get this over > > with. > > holdLock() looks nicer and there is no harm in using it here since we're not > using a Lock type that supports static analysis. My understanding was that > we just can use holdLock() with StaticLock but it was OK to use holdLock() > for other types of locks? I think the only reason CheckedLock exists is that we holdLock. There is comment that states: // FIXME: Maybe should be folded back to Lock once holdLock is not used globally.
Chris Dumez
Comment 6 2021-05-18 15:54:27 PDT
(In reply to Sam Weinig from comment #5) > (In reply to Chris Dumez from comment #3) > > (In reply to Sam Weinig from comment #2) > > > Comment on attachment 428986 [details] > > > Patch > > > > > > View in context: > > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > > + auto contextLocker = holdLock(context().graphLock()); > > > > > > I believe we are trying to move away from holdLock() and just use: > > > > > > Locker locker { context().graphLock() }; > > > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > > > We really should just do a global replace of holdLock() to get this over > > > with. > > > > holdLock() looks nicer and there is no harm in using it here since we're not > > using a Lock type that supports static analysis. My understanding was that > > we just can use holdLock() with StaticLock but it was OK to use holdLock() > > for other types of locks? > > I think the only reason CheckedLock exists is that we holdLock. There is > comment that states: > > // FIXME: Maybe should be folded back to Lock once holdLock is not used > globally. And what are you proposing for tryLock()? Keep using tryHoldLock()?
Sam Weinig
Comment 7 2021-05-18 15:55:37 PDT
(In reply to Chris Dumez from comment #4) > (In reply to Chris Dumez from comment #3) > > (In reply to Sam Weinig from comment #2) > > > Comment on attachment 428986 [details] > > > Patch > > > > > > View in context: > > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > > + auto contextLocker = holdLock(context().graphLock()); > > > > > > I believe we are trying to move away from holdLock() and just use: > > > > > > Locker locker { context().graphLock() }; > > > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > > > We really should just do a global replace of holdLock() to get this over > > > with. > > > > holdLock() looks nicer and there is no harm in using it here since we're not > > using a Lock type that supports static analysis. My understanding was that > > we just can use holdLock() with StaticLock but it was OK to use holdLock() > > for other types of locks? > > Also note that it wouldn't be: > Locker locker { context().graphLock() }; > > It would be: > Locker<RecursiveLock> locker { context().graphLock() }; > > Which would look even worse. I much prefer using auto that having to name > the lock type. Why do you have to specify RecursiveLock here? Is the argument deduction not working?
Sam Weinig
Comment 8 2021-05-18 15:58:24 PDT
(In reply to Chris Dumez from comment #6) > (In reply to Sam Weinig from comment #5) > > (In reply to Chris Dumez from comment #3) > > > (In reply to Sam Weinig from comment #2) > > > > Comment on attachment 428986 [details] > > > > Patch > > > > > > > > View in context: > > > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > > > + auto contextLocker = holdLock(context().graphLock()); > > > > > > > > I believe we are trying to move away from holdLock() and just use: > > > > > > > > Locker locker { context().graphLock() }; > > > > > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > > > > > We really should just do a global replace of holdLock() to get this over > > > > with. > > > > > > holdLock() looks nicer and there is no harm in using it here since we're not > > > using a Lock type that supports static analysis. My understanding was that > > > we just can use holdLock() with StaticLock but it was OK to use holdLock() > > > for other types of locks? > > > > I think the only reason CheckedLock exists is that we holdLock. There is > > comment that states: > > > > // FIXME: Maybe should be folded back to Lock once holdLock is not used > > globally. > > And what are you proposing for tryLock()? Keep using tryHoldLock()? I guess I would recommend we add a TryLocker class or something, not sure. But since this doesn't seem as settled as I thought it was, perhaps we should continue with holdLock/tryHoldLock for now.
Chris Dumez
Comment 9 2021-05-18 16:31:07 PDT
(In reply to Sam Weinig from comment #7) > (In reply to Chris Dumez from comment #4) > > (In reply to Chris Dumez from comment #3) > > > (In reply to Sam Weinig from comment #2) > > > > Comment on attachment 428986 [details] > > > > Patch > > > > > > > > View in context: > > > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > > > + auto contextLocker = holdLock(context().graphLock()); > > > > > > > > I believe we are trying to move away from holdLock() and just use: > > > > > > > > Locker locker { context().graphLock() }; > > > > > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > > > > > We really should just do a global replace of holdLock() to get this over > > > > with. > > > > > > holdLock() looks nicer and there is no harm in using it here since we're not > > > using a Lock type that supports static analysis. My understanding was that > > > we just can use holdLock() with StaticLock but it was OK to use holdLock() > > > for other types of locks? > > > > Also note that it wouldn't be: > > Locker locker { context().graphLock() }; > > > > It would be: > > Locker<RecursiveLock> locker { context().graphLock() }; > > > > Which would look even worse. I much prefer using auto that having to name > > the lock type. > > Why do you have to specify RecursiveLock here? Is the argument deduction not > working? My bad, I am surprised but `Locker locker { context().graphLock() };` appears to be compiling fine. I thought this only used with a CheckedLock for some reason. For tryHoldLock(), it looks like one alternative would be: auto locker = Locker<RecursiveLock>::tryLock(context().graphLock()); Should I adopt that?
Chris Dumez
Comment 10 2021-05-18 16:38:37 PDT
Sam Weinig
Comment 11 2021-05-18 17:11:12 PDT
(In reply to Chris Dumez from comment #9) > (In reply to Sam Weinig from comment #7) > > (In reply to Chris Dumez from comment #4) > > > (In reply to Chris Dumez from comment #3) > > > > (In reply to Sam Weinig from comment #2) > > > > > Comment on attachment 428986 [details] > > > > > Patch > > > > > > > > > > View in context: > > > > > https://bugs.webkit.org/attachment.cgi?id=428986&action=review > > > > > > > > > > > Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:419 > > > > > > + auto contextLocker = holdLock(context().graphLock()); > > > > > > > > > > I believe we are trying to move away from holdLock() and just use: > > > > > > > > > > Locker locker { context().graphLock() }; > > > > > > > > > > because holdLock does not play nice with ThreadSafetyAnalysis. > > > > > > > > > > We really should just do a global replace of holdLock() to get this over > > > > > with. > > > > > > > > holdLock() looks nicer and there is no harm in using it here since we're not > > > > using a Lock type that supports static analysis. My understanding was that > > > > we just can use holdLock() with StaticLock but it was OK to use holdLock() > > > > for other types of locks? > > > > > > Also note that it wouldn't be: > > > Locker locker { context().graphLock() }; > > > > > > It would be: > > > Locker<RecursiveLock> locker { context().graphLock() }; > > > > > > Which would look even worse. I much prefer using auto that having to name > > > the lock type. > > > > Why do you have to specify RecursiveLock here? Is the argument deduction not > > working? > > My bad, I am surprised but `Locker locker { context().graphLock() };` > appears to be compiling fine. I thought this only used with a CheckedLock > for some reason. > > For tryHoldLock(), it looks like one alternative would be: > auto locker = Locker<RecursiveLock>::tryLock(context().graphLock()); > > Should I adopt that? That looks good for now. I will add something to make this nicer soon and fix this up. Probably make it something like: Locker locker { context().graphLock(), Locker::Try };
Sam Weinig
Comment 12 2021-05-18 17:12:11 PDT
> My bad, I am surprised but `Locker locker { context().graphLock() };` > appears to be compiling fine. I thought this only used with a CheckedLock > for some reason. The wonders of CTAD! https://en.cppreference.com/w/cpp/language/class_template_argument_deduction
EWS
Comment 13 2021-05-18 18:51:55 PDT
Committed r277709 (237890@main): <https://commits.webkit.org/237890@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 428997 [details].
Radar WebKit Bug Importer
Comment 14 2021-05-18 18:52:19 PDT
Note You need to log in before you can comment on or make changes to this bug.