Bug 233967

Summary: Add a version of ThreadAssertions that treats UI and Web thread as the same
Product: WebKit Reporter: Cameron McCormack (:heycam) <heycam>
Component: Web Template FrameworkAssignee: Cameron McCormack (:heycam) <heycam>
Status: NEW ---    
Severity: Normal CC: benjamin, cdumez, cmarcelo, ddkilzer, ews-watchlist, kkinnunen, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=185330
Attachments:
Description Flags
Patch
none
Patch kkinnunen: review+

Description Cameron McCormack (:heycam) 2021-12-07 18:55:32 PST
ThreadAssertions has so far been used exclusively within WebCore.  Since WebCore rarely needs to distinguish between the UI thread and the Web thread, make ThreadAssertions treat them the same so that it can be used in situations where objects are interacted with in both.
Comment 1 Cameron McCormack (:heycam) 2021-12-07 18:56:24 PST
Created attachment 446277 [details]
Patch
Comment 2 Cameron McCormack (:heycam) 2021-12-07 18:59:10 PST
(In reply to Cameron McCormack (:heycam) from comment #0)
> ThreadAssertions has so far been used exclusively within WebCore.

That is completely false; it's been used exclusively within WebKit.  Perhaps ThreadAssertions needs an option to choose whether to use isMainThread() for main thread checking.
Comment 3 Cameron McCormack (:heycam) 2021-12-07 20:13:32 PST
I thought I'd templatize ThreadAssertion with a parameter that indicates whether to use isMainThread() to check for main-threadedness, but that seemed to confuse clang into thinking the relevant capability was not acquired.

Forthcoming patch just duplicates the ThreadAssertion class with this different behavior.  Comments on a better name welcome.
Comment 4 Cameron McCormack (:heycam) 2021-12-07 20:14:02 PST
Created attachment 446283 [details]
Patch
Comment 5 Kimmo Kinnunen 2021-12-07 22:23:05 PST
Comment on attachment 446283 [details]
Patch

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

> Source/WTF/wtf/ThreadAssertions.h:130
>  

would mainThread named assertion work for you instead?
example in ThreadAssertionsTest.cpp
Comment 6 Kimmo Kinnunen 2021-12-07 22:35:35 PST
Comment on attachment 446283 [details]
Patch

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

> Source/WTF/wtf/ThreadAssertions.h:76
> +class WTF_CAPABILITY_LOCK MainOrOtherThreadAssertion {

Could you name it as "SequenceAssertion".
E.g. a "sequence" is a ..sequence.. where actions happen serially. (As implemented by a work queue, or gcd queue)
Comment 7 Radar WebKit Bug Importer 2021-12-14 18:56:15 PST
<rdar://problem/86501473>