Bug 223087

Summary: Introduce WorkQueue::main() to get the main thread's work queue
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Web Template FrameworkAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, benjamin, cgarcia, cmarcelo, darin, eric.carlson, ews-watchlist, ggaren, glenn, jer.noble, philipj, sam, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch ews-feeder: commit-queue-

Description Chris Dumez 2021-03-11 13:53:38 PST
Introduce WorkQueue::main() to get the main thread's work queue. This allows us to port some more code from dispatch_queue to WorkQueue. It also simplifies some code that has to deal that sometimes needs to run on the main thread and other times on a background queue. Having a single WorkQueue type to represent both the main thread and a background queue makes writing such code more convenient.
Comment 1 Chris Dumez 2021-03-11 13:59:27 PST
Created attachment 422962 [details]
Patch
Comment 2 Chris Dumez 2021-03-11 14:09:33 PST
Created attachment 422964 [details]
Patch
Comment 3 Chris Dumez 2021-03-11 14:18:44 PST
Created attachment 422967 [details]
Patch
Comment 4 Chris Dumez 2021-03-11 14:27:14 PST
Created attachment 422972 [details]
Patch
Comment 5 Geoffrey Garen 2021-03-11 15:41:32 PST
Comment on attachment 422972 [details]
Patch

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

r=me

> Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm:214
> -    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
> +    WorkQueue::main().dispatch([this, strongThis = makeRef(*this), callbackID] {

I wonder about cases like this. Do they use WorkQueue rather than RunLoop for any specific purpose? Perhaps we should just make RunLoop::main() safe to call before main thread initialization, just like WorkQueue::main.
Comment 6 Chris Dumez 2021-03-11 15:52:23 PST
(In reply to Geoffrey Garen from comment #5)
> Comment on attachment 422972 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=422972&action=review
> 
> r=me
> 
> > Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm:214
> > -    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
> > +    WorkQueue::main().dispatch([this, strongThis = makeRef(*this), callbackID] {
> 
> I wonder about cases like this. Do they use WorkQueue rather than RunLoop
> for any specific purpose? Perhaps we should just make RunLoop::main() safe
> to call before main thread initialization, just like WorkQueue::main.

There is a CFRunLoopGetMain() so in theory, we should be able to get RunLoop::main() working before main thread initialization?
Comment 7 Geoffrey Garen 2021-03-11 16:00:01 PST
Right, I think so.
Comment 8 Chris Dumez 2021-03-11 16:01:29 PST
Comment on attachment 422972 [details]
Patch

Clearing flags on attachment: 422972

Committed r274307 (235201@main): <https://commits.webkit.org/235201@main>
Comment 9 Chris Dumez 2021-03-11 16:01:32 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2021-03-11 16:02:17 PST
<rdar://problem/75337395>