Bug 226178

Summary: Add support for better "try-lock" pattern for Locker<Lock>
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Web Template FrameworkAssignee: Chris Dumez <cdumez>
Status: ASSIGNED ---    
Severity: Normal CC: benjamin, calvaris, cmarcelo, darin, eric.carlson, ews-watchlist, ggaren, glenn, hta, jer.noble, kkinnunen, philipj, pnormand, sam, sergio, tommyw, vjaquez, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
WIP Patch
ews-feeder: commit-queue-
WIP Patch
none
WIP Patch (more complete)
none
WIP Patch (more complete) ews-feeder: commit-queue-

Description Chris Dumez 2021-05-24 08:59:44 PDT
Add support for better "try-lock" pattern for Locker<Lock>. Maybe:
```
Locker locker { DeferLock, m_lock };
if (!locker.tryLock())
    return;

// Do something.
```

I think it would be nicer than the current:
```
if (!m_lock.tryLock())
    return;

Locker locker { AdoptLock, m_lock };
// Do something.
```
Comment 1 Chris Dumez 2021-05-24 09:13:23 PDT
Created attachment 429536 [details]
WIP Patch

Very minimal patch for now as EWS didn't like it last time I tried this approach.
Comment 2 Chris Dumez 2021-05-24 09:19:23 PDT
Created attachment 429537 [details]
WIP Patch
Comment 3 Chris Dumez 2021-05-24 09:33:31 PDT
Created attachment 429540 [details]
WIP Patch (more complete)
Comment 4 Chris Dumez 2021-05-24 09:39:53 PDT
Created attachment 429542 [details]
WIP Patch (more complete)
Comment 5 Chris Dumez 2021-05-24 09:59:35 PDT
Comment on attachment 429542 [details]
WIP Patch (more complete)

View in context: https://bugs.webkit.org/attachment.cgi?id=429542&action=review

> Source/WebCore/Modules/speech/SpeechRecognitionCaptureSourceImpl.cpp:88
> +    Locker locker { DeferLock, m_dataSourceLock };

./Modules/speech/SpeechRecognitionCaptureSourceImpl.cpp:109:5: error: writing variable 'm_dataSource' requires holding mutex 'm_dataSourceLock' exclusively [-Werror,-Wthread-safety-analysis]

EWS gets this error. I don't see what I am doing wrong here and this works fine locally :/
Comment 6 Chris Dumez 2021-05-24 10:04:23 PDT
Add https://bugs.webkit.org/attachment.cgi?id=429537&action=prettypatch was building fine so the pattern seems to be working, at least in some cases..
Comment 7 Radar WebKit Bug Importer 2021-05-31 09:00:20 PDT
<rdar://problem/78689398>