Skip to content

Commit 80b2a13

Browse files
committed
[Safer CPP] Use globalDispatchQueueSingleton() instead of dispatch_get_global_queue()
https://bugs.webkit.org/show_bug.cgi?id=299014 Reviewed by Darin Adler. Use globalDispatchQueueSingleton() instead of dispatch_get_global_queue() to silence some safer cpp static analysis warnings. * Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp: (testExecutionTimeLimit): * Source/JavaScriptCore/API/tests/Regress141275.mm: (-[JSTEvaluator _callCompletionHandler:ifNeededWithError:]): * Source/JavaScriptCore/inspector/remote/cocoa/RemoteInspectorCocoa.mm: (Inspector::RemoteInspector::updateAutomaticInspectionCandidate): (Inspector::RemoteInspector::xpcConnectionFailed): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::receivedProxyApplicationSetupMessage): * Source/WTF/wtf/ParallelJobsLibdispatch.h: (WTF::ParallelEnvironment::execute): * Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp: (WTF::ConcurrentWorkQueue::apply): * Source/WTF/wtf/darwin/LibraryPathDiagnostics.mm: (WTF::initializeLibraryPathDiagnostics): * Source/WTF/wtf/mac/FileSystemMac.mm: (WTF::FileSystem::setMetadataURL): * Source/WebCore/crypto/cocoa/CryptoKeyRSAMac.cpp: (WebCore::CryptoKeyRSA::generatePair): * Source/WebCore/platform/cocoa/TelephoneNumberDetectorCocoa.cpp: (WebCore::TelephoneNumberDetector::prewarm): * Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (WebCore::ImageDecoderAVFObjC::ImageDecoderAVFObjC): * Source/WebCore/platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::schedulePrune): * Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm: (WebCore::globaVideoCaptureSerialQueue): * Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm: (WebCore::NetworkStorageSession::deleteCookie): (WebCore::NetworkStorageSession::deleteHTTPCookie const): (WebCore::NetworkStorageSession::deleteAllCookies): (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince): * Source/WebCore/testing/Internals.mm: (WebCore::Internals::emitWebCoreLogs const): (WebCore::Internals::emitLogs const): * Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm: * Source/WebKitLegacy/ios/Misc/WebUIKitSupport.mm: (LoadWebLocalizedStringsTimerCallback): * Source/WebKitLegacy/mac/Storage/WebDatabaseManager.mm: (+[WebDatabaseManager scheduleEmptyDatabaseRemoval]): * Tools/TestWebKitAPI/Tests/JavaScriptCore/JSRunLoopTimer.mm: (TestWebKitAPI::TEST(JavaScriptCore, IncrementalSweeperSecondaryThread)): * Tools/TestWebKitAPI/Tests/WebKitCocoa/NavigationAction.mm: (TEST(WKNavigationAction, NonMainThread)): * Tools/TestWebKitAPI/cocoa/TestInspectorURLSchemeHandler.mm: (-[TestInspectorURLSchemeHandler webView:startURLSchemeTask:]): Canonical link: https://commits.webkit.org/300110@main
1 parent 3ab2e2a commit 80b2a13

20 files changed

Lines changed: 41 additions & 31 deletions

File tree

‎Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <wtf/text/StringBuilder.h>
4040

4141
#if HAVE(MACH_EXCEPTIONS)
42-
#include <dispatch/dispatch.h>
42+
#include <wtf/darwin/DispatchExtras.h>
4343
#endif
4444

4545
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
@@ -533,7 +533,7 @@ int testExecutionTimeLimit()
533533
Seconds& endTimeRef = endTime;
534534

535535
dispatch_group_t group = dispatch_group_create();
536-
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
536+
dispatch_group_async(group, globalDispatchQueueSingleton(0, 0), ^{
537537
startTimeRef = CPUTime::forCurrentThread();
538538
JSEvaluateScript(contextRef, scriptRef, nullptr, nullptr, 1, &exceptionRef);
539539
endTimeRef = CPUTime::forCurrentThread();

‎Source/JavaScriptCore/API/tests/Regress141275.mm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ - (void)_setupEvaluatorThreadContextIfNeeded
282282
- (void)_callCompletionHandler:(void(^)(NSError* error))completionHandler ifNeededWithError:(NSError*)error
283283
{
284284
if (completionHandler) {
285-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
285+
dispatch_async(globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
286286
completionHandler(error);
287287
});
288288
}

‎Source/JavaScriptCore/inspector/remote/cocoa/RemoteInspectorCocoa.mm‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static bool canAccessWebInspectorMachPort()
201201
// In case debuggers fail to respond, or we cannot connect to webinspectord, assume a rejection for
202202
// automatic inspection after a short period of time.
203203
int64_t debuggerTimeoutDelay = 10;
204-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, debuggerTimeoutDelay * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
204+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, debuggerTimeoutDelay * NSEC_PER_SEC), globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
205205
Locker locker { m_mutex };
206206
if (m_automaticInspectionCandidates.remove(targetIdentifier)) {
207207
WTFLogAlways("Skipping Automatic Inspection Candidate with pageId(%u) because we failed to receive a response in time.", targetIdentifier);
@@ -457,7 +457,7 @@ static bool canAccessWebInspectorMachPort()
457457
m_shouldReconnectToRelayOnFailure = false;
458458

459459
// Schedule setting up a new connection, since we currently are holding a lock needed to create a new connection.
460-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
460+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
461461
RemoteInspector::singleton().setupXPCConnectionIfNeeded();
462462
});
463463
}
@@ -597,7 +597,7 @@ static bool canAccessWebInspectorMachPort()
597597
return;
598598

599599
m_pushScheduled = true;
600-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
600+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
601601
Locker locker { m_mutex };
602602
if (m_pushScheduled)
603603
pushListingsNow();
@@ -761,7 +761,7 @@ static bool canAccessWebInspectorMachPort()
761761
// We are a proxy application without parent process information.
762762
// Wait a bit for the information, but give up after a second.
763763
m_shouldSendParentProcessInformation = true;
764-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
764+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
765765
Locker locker { m_mutex };
766766
if (m_shouldSendParentProcessInformation)
767767
stopInternal(StopSource::XPCMessage);

‎Source/WTF/wtf/ParallelJobsLibdispatch.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#if ENABLE(THREADING_LIBDISPATCH)
3131

32-
#include <dispatch/dispatch.h>
32+
#include <wtf/darwin/DispatchExtras.h>
3333

3434
namespace WTF {
3535

@@ -54,7 +54,7 @@ class ParallelEnvironment {
5454

5555
void execute(unsigned char* parameters)
5656
{
57-
static dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
57+
static dispatch_queue_t globalQueue = globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
5858

5959
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
6060
dispatch_apply(m_numberOfJobs, globalQueue, ^(size_t i) { (*m_threadFunction)(parameters + (m_sizeOfParameter * i)); });

‎Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ WorkQueue::WorkQueue(MainTag)
104104

105105
void ConcurrentWorkQueue::apply(size_t iterations, WTF::Function<void(size_t index)>&& function)
106106
{
107-
dispatch_apply(iterations, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), makeBlockPtr([function = WTFMove(function)](size_t index) {
107+
dispatch_apply(iterations, globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), makeBlockPtr([function = WTFMove(function)](size_t index) {
108108
function(index);
109109
}).get());
110110
}

‎Source/WTF/wtf/darwin/LibraryPathDiagnostics.mm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <wtf/StringPrintStream.h>
3636
#include <wtf/UUID.h>
3737
#include <wtf/cf/TypeCastsCF.h>
38+
#include <wtf/darwin/DispatchExtras.h>
3839
#include <wtf/spi/cf/CFPrivSPI.h>
3940
#include <wtf/spi/darwin/dyldSPI.h>
4041

@@ -286,7 +287,7 @@ void initializeLibraryPathDiagnostics(void)
286287
static std::once_flag onceFlag;
287288
std::call_once(onceFlag, [] {
288289
int token = -1;
289-
notify_register_dispatch(notificationName, &token, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(int token) {
290+
notify_register_dispatch(notificationName, &token, globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(int token) {
290291
UNUSED_PARAM(token);
291292
logLibraryPathDiagnostics();
292293
});

‎Source/WTF/wtf/mac/FileSystemMac.mm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#if PLATFORM(MAC)
3030

3131
#import <wtf/cocoa/NSURLExtras.h>
32+
#import <wtf/darwin/DispatchExtras.h>
3233
#import <wtf/spi/mac/MetadataSPI.h>
3334
#import <wtf/text/WTFString.h>
3435

@@ -43,7 +44,7 @@
4344
urlString = metadataURLString;
4445

4546
// Call Metadata API on a background queue because it can take some time.
46-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [path = path.isolatedCopy(), urlString = WTFMove(urlString).isolatedCopy(), referrer = referrer.isolatedCopy()] {
47+
dispatch_async(globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [path = path.isolatedCopy(), urlString = WTFMove(urlString).isolatedCopy(), referrer = referrer.isolatedCopy()] {
4748
auto item = adoptCF(MDItemCreate(kCFAllocatorDefault, path.createCFString().get()));
4849
if (!item)
4950
return;

‎Source/WebCore/crypto/cocoa/CryptoKeyRSAMac.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <JavaScriptCore/HeapInlines.h>
3737
#include <JavaScriptCore/JSGenericTypedArrayViewInlines.h>
3838
#include <wtf/MainThread.h>
39+
#include <wtf/darwin/DispatchExtras.h>
3940

4041
namespace WebCore {
4142

@@ -283,7 +284,7 @@ void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, CryptoAlgor
283284
__block auto blockCallback(WTFMove(callback));
284285
__block auto blockFailureCallback(WTFMove(failureCallback));
285286
auto contextIdentifier = context->identifier();
286-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
287+
dispatch_async(globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
287288
CCRSACryptorRef ccPublicKey = nullptr;
288289
CCRSACryptorRef ccPrivateKey = nullptr;
289290
CCCryptorStatus status = CCRSACryptorGeneratePair(modulusLength, e, &ccPublicKey, &ccPrivateKey);

‎Source/WebCore/platform/cocoa/TelephoneNumberDetectorCocoa.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
3030

3131
#include <wtf/SoftLinking.h>
32+
#include <wtf/darwin/DispatchExtras.h>
3233

3334
#if USE(APPLE_INTERNAL_SDK)
3435
#include <DataDetectorsCore/DDDFAScanner.h>
@@ -61,7 +62,7 @@ static DDDFAScannerRef phoneNumbersScanner()
6162
void prewarm()
6263
{
6364
// Prewarm on a background queue to avoid hanging the main thread.
64-
dispatch_async(dispatch_get_global_queue(0, 0), ^{
65+
dispatch_async(globalDispatchQueueSingleton(0, 0), ^{
6566
phoneNumbersScanner();
6667
});
6768
}

‎Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#import <wtf/TZoneMallocInlines.h>
5757
#import <wtf/Vector.h>
5858
#import <wtf/cf/TypeCastsCF.h>
59+
#import <wtf/darwin/DispatchExtras.h>
5960

6061
#import "CoreVideoSoftLink.h"
6162
#import "VideoToolboxSoftLink.h"
@@ -356,7 +357,7 @@ SampleFlags flags() const override
356357
m_decompressionSession->setResourceOwner(m_resourceOwner);
357358
[m_loader updateData:data.makeContiguous()->createNSData().get() complete:NO];
358359

359-
[m_asset.get().resourceLoader setDelegate:m_loader.get() queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
360+
[m_asset.get().resourceLoader setDelegate:m_loader.get() queue:globalDispatchQueueSingleton(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
360361
[m_asset loadValuesAsynchronouslyForKeys:@[@"tracks"] completionHandler:[protectedThis = Ref { *this }] () mutable {
361362
callOnMainThread([protectedThis = WTFMove(protectedThis)] {
362363
protectedThis->setTrack(protectedThis->firstEnabledTrack());

0 commit comments

Comments
 (0)