Title: [274307] trunk
Revision
274307
Author
[email protected]
Date
2021-03-11 16:01:20 -0800 (Thu, 11 Mar 2021)

Log Message

Introduce WorkQueue::main() to get the main thread's work queue
https://bugs.webkit.org/show_bug.cgi?id=223087

Reviewed by Geoffrey Garen.

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.

Source/WebCore:

* platform/ios/WebVideoFullscreenControllerAVKit.mm:
(VideoFullscreenControllerContext::~VideoFullscreenControllerContext):
* platform/ios/wak/WebCoreThread.mm:
(WebThreadRunOnMainThread):

Source/WebKit:

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::writeFile):
(WebKit::CacheStorage::Engine::readFile):
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::retrieveOriginFromDirectory):
* NetworkProcess/cache/NetworkCacheIOChannel.h:
* NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
(WebKit::NetworkCache::IOChannel::read):
(WebKit::NetworkCache::IOChannel::write):
* NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
(WebKit::NetworkCache::IOChannel::read):
(WebKit::NetworkCache::IOChannel::write):
* NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp:
(WebKit::NetworkCache::inputStreamReadReadyCallback):
(WebKit::NetworkCache::IOChannel::read):
(WebKit::NetworkCache::IOChannel::readSyncInThread):
(WebKit::NetworkCache::outputStreamWriteReadyCallback):
(WebKit::NetworkCache::IOChannel::write):
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::dispatchReadOperation):
(WebKit::NetworkCache::Storage::dispatchWriteOperation):
(WebKit::NetworkCache::Storage::traverse):
* Shared/Cocoa/WebKit2InitializeCocoa.mm:
(WebKit::InitializeWebKit2):
* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
(WebKit::XPCServiceEventHandler):
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
(+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::scheduleActivityStateUpdate):
* UIProcess/PDF/WKPDFHUDView.mm:
(-[WKPDFHUDView initWithFrame:pluginIdentifier:page:]):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::fetchData):
(WebKit::WebsiteDataStore::fetchDataAndApply):
* UIProcess/WebsiteData/WebsiteDataStore.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager _scheduleReleaseTask]):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView requestRectsToEvadeForSelectionCommandsWithCompletionHandler:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::willOpenAppLink):
* UIProcess/mac/ServicesController.mm:
(WebKit::ServicesController::refreshExistingServices):

Source/WebKitLegacy/mac:

* Misc/WebDownload.mm:
(callOnDelegateThreadAndWait):

Source/WTF:

* wtf/WorkQueue.cpp:
(WTF::WorkQueue::main):
* wtf/WorkQueue.h:
* wtf/cocoa/WorkQueueCocoa.cpp:
(WTF::WorkQueue::constructMainWorkQueue):
(WTF::WorkQueue::WorkQueue):
* wtf/generic/WorkQueueGeneric.cpp:
(WorkQueue::constructMainWorkQueue):
(WorkQueue::WorkQueue):

Tools:

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::doAsyncTask):
* DumpRenderTree/mac/DumpRenderTree.mm:
(-[DumpRenderTree _webThreadInvoked]):
* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::doAsyncTask):
(WTR::UIScriptControllerMac::activateDataListSuggestion):
(WTR::UIScriptControllerMac::removeViewFromWindow):
(WTR::UIScriptControllerMac::addViewToWindow):
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::activateDataListSuggestion):
(WTR::UIScriptControllerMac::chooseMenuAction):
(WTR::UIScriptControllerMac::activateAtPoint):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (274306 => 274307)


--- trunk/Source/WTF/ChangeLog	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WTF/ChangeLog	2021-03-12 00:01:20 UTC (rev 274307)
@@ -1,5 +1,27 @@
 2021-03-11  Chris Dumez  <[email protected]>
 
+        Introduce WorkQueue::main() to get the main thread's work queue
+        https://bugs.webkit.org/show_bug.cgi?id=223087
+
+        Reviewed by Geoffrey Garen.
+
+        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.
+
+        * wtf/WorkQueue.cpp:
+        (WTF::WorkQueue::main):
+        * wtf/WorkQueue.h:
+        * wtf/cocoa/WorkQueueCocoa.cpp:
+        (WTF::WorkQueue::constructMainWorkQueue):
+        (WTF::WorkQueue::WorkQueue):
+        * wtf/generic/WorkQueueGeneric.cpp:
+        (WorkQueue::constructMainWorkQueue):
+        (WorkQueue::WorkQueue):
+
+2021-03-11  Chris Dumez  <[email protected]>
+
         Use BinarySemaphore in callOnMainAndWait()
         https://bugs.webkit.org/show_bug.cgi?id=223092
 

Modified: trunk/Source/WTF/wtf/WorkQueue.cpp (274306 => 274307)


--- trunk/Source/WTF/wtf/WorkQueue.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WTF/wtf/WorkQueue.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -40,6 +40,16 @@
 
 namespace WTF {
 
+WorkQueue& WorkQueue::main()
+{
+    static NeverDestroyed<RefPtr<WorkQueue>> mainWorkQueue;
+    static std::once_flag onceKey;
+    std::call_once(onceKey, [&] {
+        mainWorkQueue.get() = constructMainWorkQueue();
+    });
+    return *mainWorkQueue.get();
+}
+
 Ref<WorkQueue> WorkQueue::create(const char* name, Type type, QOS qos)
 {
     return adoptRef(*new WorkQueue(name, type, qos));

Modified: trunk/Source/WTF/wtf/WorkQueue.h (274306 => 274307)


--- trunk/Source/WTF/wtf/WorkQueue.h	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WTF/wtf/WorkQueue.h	2021-03-12 00:01:20 UTC (rev 274307)
@@ -50,6 +50,8 @@
     };
     using QOS = Thread::QOS;
 
+    WTF_EXPORT_PRIVATE static WorkQueue& main();
+
     WTF_EXPORT_PRIVATE static Ref<WorkQueue> create(const char* name, Type = Type::Serial, QOS = QOS::Default);
     ~WorkQueue() final;
 
@@ -66,8 +68,15 @@
 #endif
 
 private:
-    explicit WorkQueue(const char* name, Type, QOS);
+    WorkQueue(const char* name, Type, QOS);
 
+    static Ref<WorkQueue> constructMainWorkQueue();
+#if USE(COCOA_EVENT_LOOP)
+    explicit WorkQueue(OSObjectPtr<dispatch_queue_t>&&);
+#else
+    explicit WorkQueue(RunLoop&);
+#endif
+
     void platformInitialize(const char* name, Type, QOS);
     void platformInvalidate();
 

Modified: trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp (274306 => 274307)


--- trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -50,6 +50,16 @@
     dispatch_sync(m_dispatchQueue.get(), makeBlockPtr(WTFMove(function)).get());
 }
 
+Ref<WorkQueue> WorkQueue::constructMainWorkQueue()
+{
+    return adoptRef(*new WorkQueue(dispatch_get_main_queue()));
+}
+
+WorkQueue::WorkQueue(OSObjectPtr<dispatch_queue_t>&& dispatchQueue)
+    : m_dispatchQueue(WTFMove(dispatchQueue))
+{
+}
+
 void WorkQueue::platformInitialize(const char* name, Type type, QOS qos)
 {
     dispatch_queue_attr_t attr = type == Type::Concurrent ? DISPATCH_QUEUE_CONCURRENT : DISPATCH_QUEUE_SERIAL;

Modified: trunk/Source/WTF/wtf/generic/WorkQueueGeneric.cpp (274306 => 274307)


--- trunk/Source/WTF/wtf/generic/WorkQueueGeneric.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WTF/wtf/generic/WorkQueueGeneric.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -32,6 +32,16 @@
 
 #include <wtf/threads/BinarySemaphore.h>
 
+Ref<WorkQueue> WorkQueue::constructMainWorkQueue()
+{
+    return adoptRef(*new WorkQueue(RunLoop::main()));
+}
+
+WorkQueue::WorkQueue(RunLoop& runLoop)
+    : m_runLoop(&runLoop)
+{
+}
+
 void WorkQueue::platformInitialize(const char* name, Type, QOS)
 {
     BinarySemaphore semaphore;

Modified: trunk/Source/WebCore/ChangeLog (274306 => 274307)


--- trunk/Source/WebCore/ChangeLog	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebCore/ChangeLog	2021-03-12 00:01:20 UTC (rev 274307)
@@ -1,5 +1,22 @@
 2021-03-11  Chris Dumez  <[email protected]>
 
+        Introduce WorkQueue::main() to get the main thread's work queue
+        https://bugs.webkit.org/show_bug.cgi?id=223087
+
+        Reviewed by Geoffrey Garen.
+
+        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.
+
+        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
+        (VideoFullscreenControllerContext::~VideoFullscreenControllerContext):
+        * platform/ios/wak/WebCoreThread.mm:
+        (WebThreadRunOnMainThread):
+
+2021-03-11  Chris Dumez  <[email protected]>
+
         Use CallOnMainThreadAndWait() instead of CallAndMainThread() + BinarySemaphore
         https://bugs.webkit.org/show_bug.cgi?id=223093
 

Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm (274306 => 274307)


--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -42,9 +42,11 @@
 #import "WebCoreThreadRun.h"
 #import <QuartzCore/CoreAnimation.h>
 #import <UIKit/UIView.h>
-#import <pal/ios/UIKitSoftLink.h>
 #import <pal/spi/cocoa/QuartzCoreSPI.h>
+#import <wtf/WorkQueue.h>
 
+#import <pal/ios/UIKitSoftLink.h>
+
 using namespace WebCore;
 
 #if !(ENABLE(VIDEO_PRESENTATION_MODE) && HAVE(AVKIT))
@@ -233,7 +235,7 @@
         m_playbackModel = nullptr;
         m_fullscreenModel = nullptr;
     } else
-        dispatch_sync(dispatch_get_main_queue(), WTFMove(notifyClientsModelWasDestroyed));
+        WorkQueue::main().dispatchSync(WTFMove(notifyClientsModelWasDestroyed));
 }
 
 #pragma mark VideoFullscreenChangeObserver

Modified: trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm (274306 => 274307)


--- trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -46,6 +46,7 @@
 #import <libkern/OSAtomic.h>
 #import <objc/runtime.h>
 #import <wtf/Assertions.h>
+#import <wtf/BlockPtr.h>
 #import <wtf/MainThread.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RecursiveLockAdapter.h>
@@ -52,6 +53,7 @@
 #import <wtf/RunLoop.h>
 #import <wtf/ThreadSpecific.h>
 #import <wtf/Threading.h>
+#import <wtf/WorkQueue.h>
 #import <wtf/spi/cf/CFRunLoopSPI.h>
 #import <wtf/spi/cocoa/objcSPI.h>
 #import <wtf/text/AtomString.h>
@@ -306,9 +308,7 @@
     JSC::JSLock::DropAllLocks dropAllLocks(WebCore::commonVM());
     _WebThreadUnlock();
 
-    void (^delegateBlockCopy)() = Block_copy(delegateBlock);
-    dispatch_sync(dispatch_get_main_queue(), delegateBlockCopy);
-    Block_release(delegateBlockCopy);
+    WorkQueue::main().dispatchSync(makeBlockPtr(delegateBlock).get());
 
     _WebThreadLock();
 }

Modified: trunk/Source/WebKit/ChangeLog (274306 => 274307)


--- trunk/Source/WebKit/ChangeLog	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/ChangeLog	2021-03-12 00:01:20 UTC (rev 274307)
@@ -1,5 +1,63 @@
 2021-03-11  Chris Dumez  <[email protected]>
 
+        Introduce WorkQueue::main() to get the main thread's work queue
+        https://bugs.webkit.org/show_bug.cgi?id=223087
+
+        Reviewed by Geoffrey Garen.
+
+        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.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::writeFile):
+        (WebKit::CacheStorage::Engine::readFile):
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::Caches::retrieveOriginFromDirectory):
+        * NetworkProcess/cache/NetworkCacheIOChannel.h:
+        * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
+        (WebKit::NetworkCache::IOChannel::read):
+        (WebKit::NetworkCache::IOChannel::write):
+        * NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
+        (WebKit::NetworkCache::IOChannel::read):
+        (WebKit::NetworkCache::IOChannel::write):
+        * NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp:
+        (WebKit::NetworkCache::inputStreamReadReadyCallback):
+        (WebKit::NetworkCache::IOChannel::read):
+        (WebKit::NetworkCache::IOChannel::readSyncInThread):
+        (WebKit::NetworkCache::outputStreamWriteReadyCallback):
+        (WebKit::NetworkCache::IOChannel::write):
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::dispatchReadOperation):
+        (WebKit::NetworkCache::Storage::dispatchWriteOperation):
+        (WebKit::NetworkCache::Storage::traverse):
+        * Shared/Cocoa/WebKit2InitializeCocoa.mm:
+        (WebKit::InitializeWebKit2):
+        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
+        (WebKit::XPCServiceEventHandler):
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
+        (+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::scheduleActivityStateUpdate):
+        * UIProcess/PDF/WKPDFHUDView.mm:
+        (-[WKPDFHUDView initWithFrame:pluginIdentifier:page:]):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::fetchData):
+        (WebKit::WebsiteDataStore::fetchDataAndApply):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (-[WKProcessAssertionBackgroundTaskManager _scheduleReleaseTask]):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView requestRectsToEvadeForSelectionCommandsWithCompletionHandler:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::willOpenAppLink):
+        * UIProcess/mac/ServicesController.mm:
+        (WebKit::ServicesController::refreshExistingServices):
+
+2021-03-11  Chris Dumez  <[email protected]>
+
         Use CallOnMainThreadAndWait() instead of CallAndMainThread() + BinarySemaphore
         https://bugs.webkit.org/show_bug.cgi?id=223093
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -468,7 +468,7 @@
             FileSystem::makeAllDirectories(directoryPath);
 
         auto channel = IOChannel::open(filename, IOChannel::Type::Create, WorkQueue::QOS::Default);
-        channel->write(0, data, nullptr, [this, weakThis = WTFMove(weakThis), identifier](int error) mutable {
+        channel->write(0, data, WorkQueue::main(), [this, weakThis = WTFMove(weakThis), identifier](int error) mutable {
             ASSERT(RunLoop::isMain());
             if (!weakThis)
                 return;
@@ -505,7 +505,7 @@
             return;
         }
 
-        channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [this, weakThis = WTFMove(weakThis), identifier](const Data& data, int error) mutable {
+        channel->read(0, std::numeric_limits<size_t>::max(), WorkQueue::main(), [this, weakThis = WTFMove(weakThis), identifier](const Data& data, int error) mutable {
             RELEASE_LOG_ERROR_IF(error, CacheStorage, "CacheStorage::Engine::readFile failed with error %d", error);
 
             // FIXME: We should do the decoding in the background thread.

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -84,7 +84,7 @@
         }
 
         auto channel = IOChannel::open(filename, IOChannel::Type::Read);
-        channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [completionHandler = WTFMove(completionHandler)](const Data& data, int error) mutable {
+        channel->read(0, std::numeric_limits<size_t>::max(), WorkQueue::main(), [completionHandler = WTFMove(completionHandler)](const Data& data, int error) mutable {
             ASSERT(RunLoop::isMain());
             if (error) {
                 RELEASE_LOG_ERROR(CacheStorage, "Caches::retrieveOriginFromDirectory failed reading channel with error %d", error);

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h	2021-03-12 00:01:20 UTC (rev 274307)
@@ -50,8 +50,8 @@
 
     // Using nullptr as queue submits the result to the main queue.
     // FIXME: We should add WorkQueue::main() instead.
-    void read(size_t offset, size_t, WorkQueue*, Function<void (Data&, int error)>&&);
-    void write(size_t offset, const Data&, WorkQueue*, Function<void (int error)>&&);
+    void read(size_t offset, size_t, WorkQueue&, Function<void (Data&, int error)>&&);
+    void write(size_t offset, const Data&, WorkQueue&, Function<void (int error)>&&);
 
     const String& path() const { return m_path; }
     Type type() const { return m_type; }
@@ -68,7 +68,7 @@
     IOChannel(const String& filePath, IOChannel::Type, Optional<WorkQueue::QOS>);
 
 #if USE(GLIB)
-    void readSyncInThread(size_t offset, size_t, WorkQueue*, Function<void (Data&, int error)>&&);
+    void readSyncInThread(size_t offset, size_t, WorkQueue&, Function<void (Data&, int error)>&&);
 #endif
 
     String m_path;

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -96,12 +96,11 @@
     RELEASE_ASSERT(!m_wasDeleted.exchange(true));
 }
 
-void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void (Data&, int error)>&& completionHandler)
+void IOChannel::read(size_t offset, size_t size, WorkQueue& queue, Function<void (Data&, int error)>&& completionHandler)
 {
     RefPtr<IOChannel> channel(this);
     bool didCallCompletionHandler = false;
-    auto dispatchQueue = queue ? queue->dispatchQueue() : dispatch_get_main_queue();
-    dispatch_io_read(m_dispatchIO.get(), offset, size, dispatchQueue, makeBlockPtr([channel, completionHandler = WTFMove(completionHandler), didCallCompletionHandler](bool done, dispatch_data_t fileData, int error) mutable {
+    dispatch_io_read(m_dispatchIO.get(), offset, size, queue.dispatchQueue(), makeBlockPtr([channel, completionHandler = WTFMove(completionHandler), didCallCompletionHandler](bool done, dispatch_data_t fileData, int error) mutable {
         ASSERT_UNUSED(done, done || !didCallCompletionHandler);
         if (didCallCompletionHandler)
             return;
@@ -112,12 +111,11 @@
     }).get());
 }
 
-void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void (int error)>&& completionHandler)
+void IOChannel::write(size_t offset, const Data& data, WorkQueue& queue, Function<void (int error)>&& completionHandler)
 {
     RefPtr<IOChannel> channel(this);
     auto dispatchData = data.dispatchData();
-    auto dispatchQueue = queue ? queue->dispatchQueue() : dispatch_get_main_queue();
-    dispatch_io_write(m_dispatchIO.get(), offset, dispatchData, dispatchQueue, makeBlockPtr([channel, completionHandler = WTFMove(completionHandler)](bool done, dispatch_data_t fileData, int error) mutable {
+    dispatch_io_write(m_dispatchIO.get(), offset, dispatchData, queue.dispatchQueue(), makeBlockPtr([channel, completionHandler = WTFMove(completionHandler)](bool done, dispatch_data_t fileData, int error) mutable {
         ASSERT_UNUSED(done, done);
         auto callback = WTFMove(completionHandler);
         callback(error);

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -55,20 +55,9 @@
     FileSystem::closeFile(m_fileDescriptor);
 }
 
-static inline void runTaskInQueue(Function<void()>&& task, WorkQueue* queue)
+void IOChannel::read(size_t offset, size_t size, WorkQueue& queue, Function<void(Data&, int error)>&& completionHandler)
 {
-    if (queue) {
-        queue->dispatch(WTFMove(task));
-        return;
-    }
-
-    // Using nullptr as queue submits the result to the main context.
-    RunLoop::main().dispatch(WTFMove(task));
-}
-
-void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
-{
-    runTaskInQueue([this, protectedThis = makeRef(*this), offset, size, completionHandler = WTFMove(completionHandler)] {
+    queue.dispatch([this, protectedThis = makeRef(*this), offset, size, completionHandler = WTFMove(completionHandler)] {
         long long fileSize;
         if (!FileSystem::getFileSize(m_fileDescriptor, fileSize) || fileSize > std::numeric_limits<size_t>::max()) {
             Data data;
@@ -83,17 +72,17 @@
         err = err < 0 ? err : 0;
         auto data = ""
         completionHandler(data, err);
-    }, queue);
+    });
 }
 
-void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void(int error)>&& completionHandler)
+void IOChannel::write(size_t offset, const Data& data, WorkQueue& queue, Function<void(int error)>&& completionHandler)
 {
-    runTaskInQueue([this, protectedThis = makeRef(*this), offset, data, completionHandler = WTFMove(completionHandler)] {
+    queue.dispatch([this, protectedThis = makeRef(*this), offset, data, completionHandler = WTFMove(completionHandler)] {
         FileSystem::seekFile(m_fileDescriptor, offset, FileSystem::FileSeekOrigin::Beginning);
         int err = FileSystem::writeToFile(m_fileDescriptor, reinterpret_cast<const char*>(data.data()), data.size());
         err = err < 0 ? err : 0;
         completionHandler(err);
-    }, queue);
+    });
 }
 
 } // namespace NetworkCache

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -68,17 +68,6 @@
     RELEASE_ASSERT(!m_wasDeleted.exchange(true));
 }
 
-static inline void runTaskInQueue(Function<void()>&& task, WorkQueue* queue)
-{
-    if (queue) {
-        queue->dispatch(WTFMove(task));
-        return;
-    }
-
-    // Using nullptr as queue submits the result to the main context.
-    RunLoop::main().dispatch(WTFMove(task));
-}
-
 static void fillDataFromReadBuffer(GBytes* readBuffer, size_t size, Data& data)
 {
     GRefPtr<GBytes> buffer;
@@ -103,7 +92,7 @@
 
     RefPtr<IOChannel> channel;
     GRefPtr<GBytes> buffer;
-    RefPtr<WorkQueue> queue;
+    Ref<WorkQueue> queue;
     size_t bytesToRead;
     Function<void(Data&, int error)> completionHandler;
     Data data;
@@ -114,18 +103,16 @@
     std::unique_ptr<ReadAsyncData> asyncData(static_cast<ReadAsyncData*>(userData));
     gssize bytesRead = g_input_stream_read_finish(stream, result, nullptr);
     if (bytesRead == -1) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+        asyncData->queue->dispatch([asyncData = WTFMove(asyncData)] {
             asyncData->completionHandler(asyncData->data, -1);
-        }, queue);
+        });
         return;
     }
 
     if (!bytesRead) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+        asyncData->queue->dispatch([asyncData = WTFMove(asyncData)] {
             asyncData->completionHandler(asyncData->data, 0);
-        }, queue);
+        });
         return;
     }
 
@@ -134,10 +121,9 @@
 
     size_t pendingBytesToRead = asyncData->bytesToRead - asyncData->data.size();
     if (!pendingBytesToRead) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+        asyncData->queue->dispatch([asyncData = WTFMove(asyncData)] {
             asyncData->completionHandler(asyncData->data, 0);
-        }, queue);
+        });
         return;
     }
 
@@ -148,14 +134,14 @@
         reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData.release());
 }
 
-void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
+void IOChannel::read(size_t offset, size_t size, WorkQueue& queue, Function<void(Data&, int error)>&& completionHandler)
 {
     RefPtr<IOChannel> protectedThis(this);
     if (!m_inputStream) {
-        runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+        queue.dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
             Data data;
             completionHandler(data, -1);
-        }, queue);
+        });
         return;
     }
 
@@ -174,11 +160,11 @@
         reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData);
 }
 
-void IOChannel::readSyncInThread(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
+void IOChannel::readSyncInThread(size_t offset, size_t size, WorkQueue& queue, Function<void(Data&, int error)>&& completionHandler)
 {
     ASSERT(!RunLoop::isMain());
 
-    Thread::create("IOChannel::readSync", [this, protectedThis = makeRef(*this), size, queue, completionHandler = WTFMove(completionHandler)] () mutable {
+    Thread::create("IOChannel::readSync", [this, protectedThis = makeRef(*this), size, queue = makeRef(queue), completionHandler = WTFMove(completionHandler)] () mutable {
         size_t bufferSize = std::min(size, gDefaultReadBufferSize);
         uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
         GRefPtr<GBytes> readBuffer = adoptGRef(g_bytes_new_with_free_func(bufferData, bufferSize, fastFree, bufferData));
@@ -189,10 +175,10 @@
             // FIXME: implement offset.
             gssize bytesRead = g_input_stream_read(m_inputStream.get(), const_cast<void*>(g_bytes_get_data(readBuffer.get(), nullptr)), bytesToRead, nullptr, nullptr);
             if (bytesRead == -1) {
-                runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+                queue->dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
                     Data data;
                     completionHandler(data, -1);
-                }, queue);
+                });
                 return;
             }
 
@@ -206,10 +192,10 @@
             bytesToRead = std::min(pendingBytesToRead, g_bytes_get_size(readBuffer.get()));
         } while (pendingBytesToRead);
 
-        runTaskInQueue([protectedThis = WTFMove(protectedThis), buffer = GRefPtr<GBytes>(data.bytes()), completionHandler = WTFMove(completionHandler)]() mutable {
+        queue->dispatch([protectedThis = WTFMove(protectedThis), buffer = GRefPtr<GBytes>(data.bytes()), completionHandler = WTFMove(completionHandler)]() mutable {
             Data data = { WTFMove(buffer) };
             completionHandler(data, 0);
-        }, queue);
+        });
     })->detach();
 }
 
@@ -218,7 +204,7 @@
 
     RefPtr<IOChannel> channel;
     GRefPtr<GBytes> buffer;
-    RefPtr<WorkQueue> queue;
+    Ref<WorkQueue> queue;
     Function<void(int error)> completionHandler;
 };
 
@@ -227,19 +213,17 @@
     std::unique_ptr<WriteAsyncData> asyncData(static_cast<WriteAsyncData*>(userData));
     gssize bytesWritten = g_output_stream_write_finish(stream, result, nullptr);
     if (bytesWritten == -1) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+        asyncData->queue->dispatch([asyncData = WTFMove(asyncData)] {
             asyncData->completionHandler(-1);
-        }, queue);
+        });
         return;
     }
 
     gssize pendingBytesToWrite = g_bytes_get_size(asyncData->buffer.get()) - bytesWritten;
     if (!pendingBytesToWrite) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+        asyncData->queue->dispatch([asyncData = WTFMove(asyncData)] {
             asyncData->completionHandler(0);
-        }, queue);
+        });
         return;
     }
 
@@ -250,21 +234,21 @@
         reinterpret_cast<GAsyncReadyCallback>(outputStreamWriteReadyCallback), asyncData.release());
 }
 
-void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void(int error)>&& completionHandler)
+void IOChannel::write(size_t offset, const Data& data, WorkQueue& queue, Function<void(int error)>&& completionHandler)
 {
     RefPtr<IOChannel> protectedThis(this);
     if (!m_outputStream && !m_ioStream) {
-        runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+        queue.dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
             completionHandler(-1);
-        }, queue);
+        });
         return;
     }
 
     GOutputStream* stream = m_outputStream ? m_outputStream.get() : g_io_stream_get_output_stream(G_IO_STREAM(m_ioStream.get()));
     if (!stream) {
-        runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+        queue.dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
             completionHandler(-1);
-        }, queue);
+        });
         return;
     }
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp (274306 => 274307)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -738,7 +738,7 @@
         readOperation.timings.recordIOStartTime = MonotonicTime::now();
 
         auto channel = IOChannel::open(recordPath, IOChannel::Type::Read);
-        channel->read(0, std::numeric_limits<size_t>::max(), &ioQueue(), [this, &readOperation](const Data& fileData, int error) {
+        channel->read(0, std::numeric_limits<size_t>::max(), ioQueue(), [this, &readOperation](const Data& fileData, int error) {
             readOperation.timings.recordIOEndTime = MonotonicTime::now();
             if (!error)
                 readRecord(readOperation, fileData);
@@ -877,7 +877,7 @@
 
         auto channel = IOChannel::open(recordPath, IOChannel::Type::Create);
         size_t recordSize = recordData.size();
-        channel->write(0, recordData, nullptr, [this, &writeOperation, recordSize](int error) {
+        channel->write(0, recordData, WorkQueue::main(), [this, &writeOperation, recordSize](int error) {
             // On error the entry still stays in the contents filter until next synchronization.
             m_approximateRecordsSize += recordSize;
             finishWriteOperation(writeOperation, error);
@@ -986,7 +986,7 @@
             ++traverseOperation.activeCount;
 
             auto channel = IOChannel::open(recordPath, IOChannel::Type::Read);
-            channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [this, &traverseOperation, worth, bodyShareCount](Data& fileData, int) {
+            channel->read(0, std::numeric_limits<size_t>::max(), WorkQueue::main(), [this, &traverseOperation, worth, bodyShareCount](Data& fileData, int) {
                 RecordMetaData metaData;
                 Data headerData;
                 if (decodeRecordHeader(fileData, metaData, headerData, m_salt)) {

Modified: trunk/Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm (274306 => 274307)


--- trunk/Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -32,7 +32,7 @@
 #import <mutex>
 #import <wtf/MainThread.h>
 #import <wtf/RefCounted.h>
-#import <wtf/RunLoop.h>
+#import <wtf/WorkQueue.h>
 
 #if PLATFORM(IOS_FAMILY)
 #import <WebCore/WebCoreThreadSystemInterface.h>
@@ -67,7 +67,7 @@
         if ([NSThread isMainThread] || linkedOnOrAfter(WebCore::SDKVersion::FirstWithInitializeWebKit2MainThreadAssertion))
             runInitializationCode();
         else
-            dispatch_sync_f(dispatch_get_main_queue(), nullptr, runInitializationCode);
+            WorkQueue::main().dispatchSync([] { runInitializationCode(); });
     });
 }
 

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm (274306 => 274307)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -117,7 +117,7 @@
                 if (fd != -1)
                     dup2(fd, STDERR_FILENO);
 
-                dispatch_sync(dispatch_get_main_queue(), ^{
+                WorkQueue::main().dispatchSync([&] {
                     initializerFunctionPtr(peer, event, priorityBoostMessage.get().get());
 
                     setAppleLanguagesPreference();

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -110,9 +110,9 @@
         WebKit::WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
     else {
         // This cannot be RunLoop::main().dispatch because it is called before the main runloop is initialized.  See rdar://problem/73615999
-        dispatch_async(dispatch_get_main_queue(), makeBlockPtr([scheme = retainPtr(scheme)] {
+        WorkQueue::main().dispatch([scheme = retainPtr(scheme)] {
             WebKit::WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme.get());
-        }).get());
+        });
     }
 }
 
@@ -122,9 +122,9 @@
         WebKit::WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
     else {
         // This cannot be RunLoop::main().dispatch because it is called before the main runloop is initialized.  See rdar://problem/73615999
-        dispatch_async(dispatch_get_main_queue(), makeBlockPtr([scheme = retainPtr(scheme)] {
+        WorkQueue::main().dispatch([scheme = retainPtr(scheme)] {
             WebKit::WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme.get());
-        }).get());
+        });
     }
 }
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -522,7 +522,7 @@
             // We can't call dispatchActivityStateChange directly underneath this commit handler, because it has side-effects
             // that may result in other frameworks trying to install commit handlers for the same phase, which is not allowed.
             // So, dispatch_async here; we only care that the activity state change doesn't apply until after the active commit is complete.
-            dispatch_async(dispatch_get_main_queue(), [weakThis] {
+            WorkQueue::main().dispatch([weakThis] {
                 auto protectedThis = makeRefPtr(weakThis.get());
                 if (!protectedThis)
                     return;

Modified: trunk/Source/WebKit/UIProcess/PDF/WKPDFHUDView.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/PDF/WKPDFHUDView.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/PDF/WKPDFHUDView.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -109,7 +109,7 @@
     [self setFrame:frame];
 
     WeakObjCPtr<WKPDFHUDView> weakSelf = self;
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(initialHideTimeInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+    WorkQueue::main().dispatchAfter(Seconds { initialHideTimeInterval }, [weakSelf] {
         [weakSelf _hideTimerFired];
     });
     return self;

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-03-12 00:01:20 UTC (rev 274307)
@@ -305,14 +305,14 @@
 
 void WebsiteDataStore::fetchData(OptionSet<WebsiteDataType> dataTypes, OptionSet<WebsiteDataFetchOption> fetchOptions, Function<void(Vector<WebsiteDataRecord>)>&& completionHandler)
 {
-    fetchDataAndApply(dataTypes, fetchOptions, nullptr, WTFMove(completionHandler));
+    fetchDataAndApply(dataTypes, fetchOptions, WorkQueue::main(), WTFMove(completionHandler));
 }
 
-void WebsiteDataStore::fetchDataAndApply(OptionSet<WebsiteDataType> dataTypes, OptionSet<WebsiteDataFetchOption> fetchOptions, RefPtr<WorkQueue>&& queue, Function<void(Vector<WebsiteDataRecord>)>&& apply)
+void WebsiteDataStore::fetchDataAndApply(OptionSet<WebsiteDataType> dataTypes, OptionSet<WebsiteDataFetchOption> fetchOptions, Ref<WorkQueue>&& queue, Function<void(Vector<WebsiteDataRecord>)>&& apply)
 {
     class CallbackAggregator final : public ThreadSafeRefCounted<CallbackAggregator, WTF::DestructionThread::MainRunLoop> {
     public:
-        static Ref<CallbackAggregator> create(OptionSet<WebsiteDataFetchOption> fetchOptions, RefPtr<WorkQueue>&& queue, Function<void(Vector<WebsiteDataRecord>)>&& apply, WebsiteDataStore& dataStore)
+        static Ref<CallbackAggregator> create(OptionSet<WebsiteDataFetchOption> fetchOptions, Ref<WorkQueue>&& queue, Function<void(Vector<WebsiteDataRecord>)>&& apply, WebsiteDataStore& dataStore)
         {
             return adoptRef(*new CallbackAggregator(fetchOptions, WTFMove(queue), WTFMove(apply), dataStore));
         }
@@ -324,16 +324,11 @@
             Vector<WebsiteDataRecord> records;
             records.reserveInitialCapacity(m_websiteDataRecords.size());
             for (auto& record : m_websiteDataRecords.values())
-                records.uncheckedAppend(m_queue ? crossThreadCopy(record) : WTFMove(record));
+                records.uncheckedAppend(m_queue.ptr() != &WorkQueue::main() ? crossThreadCopy(record) : WTFMove(record));
 
-            auto processRecords = [apply = WTFMove(m_apply), records = WTFMove(records)] () mutable {
+            m_queue->dispatch([apply = WTFMove(m_apply), records = WTFMove(records)] () mutable {
                 apply(WTFMove(records));
-            };
-
-            if (m_queue)
-                m_queue->dispatch(WTFMove(processRecords));
-            else
-                RunLoop::main().dispatch(WTFMove(processRecords));
+            });
         }
 
         const OptionSet<WebsiteDataFetchOption>& fetchOptions() const { return m_fetchOptions; }
@@ -426,7 +421,7 @@
         }
 
 private:
-        CallbackAggregator(OptionSet<WebsiteDataFetchOption> fetchOptions, RefPtr<WorkQueue>&& queue, Function<void(Vector<WebsiteDataRecord>)>&& apply, WebsiteDataStore& dataStore)
+        CallbackAggregator(OptionSet<WebsiteDataFetchOption> fetchOptions, Ref<WorkQueue>&& queue, Function<void(Vector<WebsiteDataRecord>)>&& apply, WebsiteDataStore& dataStore)
             : m_fetchOptions(fetchOptions)
             , m_queue(WTFMove(queue))
             , m_apply(WTFMove(apply))
@@ -436,7 +431,7 @@
         }
 
         const OptionSet<WebsiteDataFetchOption> m_fetchOptions;
-        RefPtr<WorkQueue> m_queue;
+        Ref<WorkQueue> m_queue;
         Function<void(Vector<WebsiteDataRecord>)> m_apply;
 
         HashMap<String, WebsiteDataRecord> m_websiteDataRecords;

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-03-12 00:01:20 UTC (rev 274307)
@@ -357,7 +357,7 @@
     void addTestDomains() const;
 #endif
 
-    void fetchDataAndApply(OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, RefPtr<WorkQueue>&&, Function<void(Vector<WebsiteDataRecord>)>&& apply);
+    void fetchDataAndApply(OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, Ref<WorkQueue>&&, Function<void(Vector<WebsiteDataRecord>)>&& apply);
 
     void platformInitialize();
     void platformDestroy();

Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -36,6 +36,7 @@
 #import <wtf/RunLoop.h>
 #import <wtf/Vector.h>
 #import <wtf/WeakHashSet.h>
+#import <wtf/WorkQueue.h>
 
 using WebKit::ProcessAndUIAssertion;
 
@@ -135,15 +136,10 @@
         return;
 
     RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager: _scheduleReleaseTask because the expiration handler has been called", self);
-    _pendingTaskReleaseTask = dispatch_block_create((dispatch_block_flags_t)0, ^{
+    WorkQueue::main().dispatchAfter(releaseBackgroundTaskAfterExpirationDelay, [self, retainedSelf = retainPtr(self)] {
         _pendingTaskReleaseTask = nil;
         [self _releaseBackgroundTask];
     });
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, releaseBackgroundTaskAfterExpirationDelay.value() * NSEC_PER_SEC), dispatch_get_main_queue(), _pendingTaskReleaseTask);
-#if !__has_feature(objc_arc)
-    // dispatch_async() does a Block_copy() / Block_release() on behalf of the caller.
-    Block_release(_pendingTaskReleaseTask);
-#endif
 }
 
 - (void)_cancelPendingReleaseTask

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -4229,8 +4229,8 @@
     }
 
     // Give the page some time to present custom editing UI before attempting to detect and evade it.
-    auto delayBeforeShowingCalloutBar = (0.25_s).nanoseconds();
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delayBeforeShowingCalloutBar), dispatch_get_main_queue(), [completion = makeBlockPtr(completionHandler), weakSelf = WeakObjCPtr<WKContentView>(self)] () mutable {
+    auto delayBeforeShowingCalloutBar = 0.25_s;
+    WorkQueue::main().dispatchAfter(delayBeforeShowingCalloutBar, [completion = makeBlockPtr(completionHandler), weakSelf = WeakObjCPtr<WKContentView>(self)] () mutable {
         if (!weakSelf) {
             completion(@[ ]);
             return;

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -1505,7 +1505,7 @@
     // We chose 25 seconds because the system only gives us 30 seconds and we don't want to get too close to that limit
     // to avoid assertion invalidation (or even termination).
     m_openingAppLinkActivity = process().throttler().backgroundActivity("Opening AppLink"_s).moveToUniquePtr();
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_SEC), dispatch_get_main_queue(), [weakThis = makeWeakPtr(*this)] {
+    WorkQueue::main().dispatchAfter(25_s, [weakThis = makeWeakPtr(*this)] {
         if (weakThis)
             weakThis->m_openingAppLinkActivity = nullptr;
     });

Modified: trunk/Source/WebKit/UIProcess/mac/ServicesController.mm (274306 => 274307)


--- trunk/Source/WebKit/UIProcess/mac/ServicesController.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKit/UIProcess/mac/ServicesController.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -104,7 +104,7 @@
         static NeverDestroyed<RetainPtr<NSAttributedString>> attributedStringWithRichContent;
         static std::once_flag attributedStringWithRichContentOnceFlag;
         std::call_once(attributedStringWithRichContentOnceFlag, [&] {
-            dispatch_sync(dispatch_get_main_queue(), [&] {
+            WorkQueue::main().dispatchSync([&] {
                 auto attachment = adoptNS([[NSTextAttachment alloc] init]);
                 auto cell = adoptNS([[NSTextAttachmentCell alloc] initImageCell:image]);
                 [attachment setAttachmentCell:cell.get()];

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (274306 => 274307)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-03-12 00:01:20 UTC (rev 274307)
@@ -1,3 +1,18 @@
+2021-03-11  Chris Dumez  <[email protected]>
+
+        Introduce WorkQueue::main() to get the main thread's work queue
+        https://bugs.webkit.org/show_bug.cgi?id=223087
+
+        Reviewed by Geoffrey Garen.
+
+        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.
+
+        * Misc/WebDownload.mm:
+        (callOnDelegateThreadAndWait):
+
 2021-03-10  Chris Dumez  <[email protected]>
 
         Use RetainPtr<> / OSObjectPtr<> more in WebKit

Modified: trunk/Source/WebKitLegacy/mac/Misc/WebDownload.mm (274306 => 274307)


--- trunk/Source/WebKitLegacy/mac/Misc/WebDownload.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebDownload.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -41,6 +41,7 @@
 #import <pal/spi/cocoa/NSURLDownloadSPI.h>
 #import <wtf/Assertions.h>
 #import <wtf/MainThread.h>
+#import <wtf/WorkQueue.h>
 #import <wtf/spi/darwin/dyldSPI.h>
 
 static bool shouldCallOnNetworkThread()
@@ -65,8 +66,11 @@
 {
     if (shouldCallOnNetworkThread() || isMainThread())
         work();
-    else
-        dispatch_sync(dispatch_get_main_queue(), work);
+    else {
+        WorkQueue::main().dispatchSync([work = WTFMove(work)]() mutable {
+            work();
+        });
+    }
 }
 
 using namespace WebCore;

Modified: trunk/Tools/ChangeLog (274306 => 274307)


--- trunk/Tools/ChangeLog	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Tools/ChangeLog	2021-03-12 00:01:20 UTC (rev 274307)
@@ -1,3 +1,29 @@
+2021-03-11  Chris Dumez  <[email protected]>
+
+        Introduce WorkQueue::main() to get the main thread's work queue
+        https://bugs.webkit.org/show_bug.cgi?id=223087
+
+        Reviewed by Geoffrey Garen.
+
+        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.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptControllerIOS::doAsyncTask):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (-[DumpRenderTree _webThreadInvoked]):
+        * DumpRenderTree/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptControllerMac::doAsyncTask):
+        (WTR::UIScriptControllerMac::activateDataListSuggestion):
+        (WTR::UIScriptControllerMac::removeViewFromWindow):
+        (WTR::UIScriptControllerMac::addViewToWindow):
+        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptControllerMac::activateDataListSuggestion):
+        (WTR::UIScriptControllerMac::chooseMenuAction):
+        (WTR::UIScriptControllerMac::activateAtPoint):
+
 2021-03-11  Alex Christensen  <[email protected]>
 
         Revert r260302

Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (274306 => 274307)


--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -34,6 +34,7 @@
 #import <WebCore/FloatRect.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/MainThread.h>
+#import <wtf/WorkQueue.h>
 
 extern RetainPtr<DumpRenderTreeBrowserView> gWebBrowserView;
 extern RetainPtr<DumpRenderTreeWebScrollView> gWebScrollView;
@@ -49,11 +50,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, protectedThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerIOS::zoomToScale(double scale, JSValueRef callback)
@@ -60,8 +61,7 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    RefPtr<UIScriptController> protectedThis(this);
-    dispatch_async(dispatch_get_main_queue(), ^{
+    WorkQueue::main().dispatch([this, protectedThis = makeRef(*this), scale, callbackID] {
         [gWebScrollView zoomToScale:scale animated:YES completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
             if (!m_context)
                 return;

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (274306 => 274307)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -105,6 +105,7 @@
 #import <wtf/RetainPtr.h>
 #import <wtf/Threading.h>
 #import <wtf/UniqueArray.h>
+#import <wtf/WorkQueue.h>
 #import <wtf/cocoa/CrashReporter.h>
 #import <wtf/cocoa/VectorCocoa.h>
 #import <wtf/text/StringBuilder.h>
@@ -1238,7 +1239,7 @@
 - (void)_webThreadInvoked
 {
     ASSERT(WebThreadIsCurrent());
-    dispatch_async(dispatch_get_main_queue(), ^{
+    WorkQueue::main().dispatch([self, retainedSelf = retainPtr(self)] {
         [self _webThreadEventLoopHasRun];
     });
 }

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (274306 => 274307)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -38,7 +38,7 @@
 #import <WebKit/WebPreferences.h>
 #import <WebKit/WebViewPrivate.h>
 #import <pal/spi/mac/NSTextInputContextSPI.h>
-#import <wtf/BlockPtr.h>
+#import <wtf/WorkQueue.h>
 
 namespace WTR {
 
@@ -51,11 +51,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, protectedThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerMac::replaceTextAtRange(JSStringRef text, int location, int length)
@@ -107,11 +107,11 @@
     UNUSED_PARAM(index);
 
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, protectedThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerMac::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
@@ -130,11 +130,11 @@
     WebView *webView = [mainFrame webView];
     [webView removeFromSuperview];
 
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, protectedThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerMac::addViewToWindow(JSValueRef callback)
@@ -144,11 +144,11 @@
     WebView *webView = [mainFrame webView];
     [[mainWindow contentView] addSubview:webView];
 
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, protectedThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerMac::toggleCapsLock(JSValueRef callback)

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (274306 => 274307)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2021-03-11 23:59:14 UTC (rev 274306)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2021-03-12 00:01:20 UTC (rev 274307)
@@ -45,6 +45,7 @@
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/WKWebViewPrivateForTesting.h>
 #import <wtf/BlockPtr.h>
+#import <wtf/WorkQueue.h>
 
 namespace WTR {
 
@@ -151,7 +152,7 @@
     [table selectRowIndexes:[NSIndexSet indexSetWithIndex:index] byExtendingSelection:NO];
 
     // Send the action after a short delay to simulate normal user interaction.
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), [this, protectedThis = makeRefPtr(*this), callbackID, table] {
+    WorkQueue::main().dispatchAfter(50_ms, [this, protectedThis = makeRefPtr(*this), callbackID, table] {
         if ([table window])
             [table sendAction:[table action] to:[table target]];
 
@@ -210,11 +211,11 @@
         [activeMenu cancelTracking];
     }
 
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerMac::beginBackSwipe(JSValueRef callback)
@@ -287,11 +288,11 @@
     eventSender->mouseDown(0, 0);
     eventSender->mouseUp(0, 0);
 
-    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+    WorkQueue::main().dispatch([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get());
+    });
 }
 
 void UIScriptControllerMac::copyText(JSStringRef text)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to