Remove std::lock_guard
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Mar 2020 05:01:30 +0000 (05:01 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Mar 2020 05:01:30 +0000 (05:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206451

Reviewed by Anders Carlsson.

Source/bmalloc:

* bmalloc/Mutex.h:

Source/JavaScriptCore:

* API/JSVirtualMachine.mm:
(+[JSVMWrapperCache addWrapper:forJSContextGroupRef:]):
(+[JSVMWrapperCache wrapperForJSContextGroupRef:]):
* API/glib/JSCVirtualMachine.cpp:
(addWrapper):
(removeWrapper):
* heap/HeapSnapshotBuilder.cpp:
(JSC::HeapSnapshotBuilder::analyzeNode):
(JSC::HeapSnapshotBuilder::analyzeEdge):
(JSC::HeapSnapshotBuilder::analyzePropertyNameEdge):
(JSC::HeapSnapshotBuilder::analyzeVariableNameEdge):
(JSC::HeapSnapshotBuilder::analyzeIndexEdge):
(JSC::HeapSnapshotBuilder::setOpaqueRootReachabilityReasonForCell):
* heap/MachineStackMarker.cpp:
(JSC::MachineThreads::tryCopyOtherThreadStacks):
* runtime/JSRunLoopTimer.cpp:
(JSC::JSRunLoopTimer::timerDidFire):

Source/WebCore:

* Modules/webaudio/AudioBufferSourceNode.cpp:
(WebCore::AudioBufferSourceNode::setBuffer):
* Modules/webaudio/AudioParamTimeline.cpp:
(WebCore::AudioParamTimeline::insertEvent):
(WebCore::AudioParamTimeline::cancelScheduledValues):
* Modules/webaudio/ConvolverNode.cpp:
(WebCore::ConvolverNode::reset):
(WebCore::ConvolverNode::setBuffer):
* Modules/webaudio/MediaElementAudioSourceNode.cpp:
(WebCore::MediaElementAudioSourceNode::setFormat):
* Modules/webaudio/MediaStreamAudioSourceNode.cpp:
(WebCore::MediaStreamAudioSourceNode::setFormat):
* Modules/webaudio/OscillatorNode.cpp:
(WebCore::OscillatorNode::setPeriodicWave):
* Modules/webaudio/PannerNode.cpp:
(WebCore::PannerNode::setPanningModel):
* Modules/webaudio/WaveShaperProcessor.cpp:
(WebCore::WaveShaperProcessor::setCurve):
(WebCore::WaveShaperProcessor::setOversample):
* Modules/webdatabase/Database.cpp:
(WebCore::Database::Database):
(WebCore::Database::performOpenAndVerify):
(WebCore::Database::closeDatabase):
(WebCore::Database::getCachedVersion const):
(WebCore::Database::setCachedVersion):
* Modules/webdatabase/DatabaseManager.cpp:
(WebCore::DatabaseManager::addProposedDatabase):
(WebCore::DatabaseManager::removeProposedDatabase):
(WebCore::DatabaseManager::fullPathForDatabase):
(WebCore::DatabaseManager::detailsForNameAndOrigin):
* crypto/CryptoAlgorithmRegistry.cpp:
(WebCore::CryptoAlgorithmRegistry::identifier):
(WebCore::CryptoAlgorithmRegistry::name):
(WebCore::CryptoAlgorithmRegistry::create):
(WebCore::CryptoAlgorithmRegistry::registerAlgorithm):
* inspector/agents/WebHeapAgent.cpp:
(WebCore::SendGarbageCollectionEventsTask::addGarbageCollection):
(WebCore::SendGarbageCollectionEventsTask::reset):
(WebCore::SendGarbageCollectionEventsTask::timerFired):
* page/scrolling/ScrollingThread.cpp:
(WebCore::ScrollingThread::dispatch):
(WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):
* page/scrolling/generic/ScrollingThreadGeneric.cpp:
(WebCore::ScrollingThread::initializeRunLoop):
* page/scrolling/mac/ScrollingThreadMac.mm:
(WebCore::ScrollingThread::initializeRunLoop):
* platform/audio/ReverbConvolver.cpp:
(WebCore::ReverbConvolver::~ReverbConvolver):
* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
(WebCore::AudioSourceProviderAVFObjC::~AudioSourceProviderAVFObjC):
(WebCore::AudioSourceProviderAVFObjC::finalizeCallback):
(WebCore::AudioSourceProviderAVFObjC::prepareCallback):
(WebCore::AudioSourceProviderAVFObjC::unprepareCallback):
(WebCore::AudioSourceProviderAVFObjC::processCallback):
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontDatabase::collectionForFamily):
(WebCore::FontDatabase::clear):
* platform/ios/wak/WebCoreThreadRun.cpp:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
(WebCore::WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC):
(WebCore::WebAudioSourceProviderAVFObjC::prepare):
(WebCore::WebAudioSourceProviderAVFObjC::unprepare):
* platform/network/cf/LoaderRunLoopCF.cpp:
(WebCore::loaderRunLoop):
* platform/sql/SQLiteDatabase.cpp:
(WebCore::SQLiteDatabase::setIsDatabaseOpeningForbidden):
(WebCore::SQLiteDatabase::open):
* platform/sql/SQLiteDatabaseTracker.cpp:
(WebCore::SQLiteDatabaseTracker::setClient):
(WebCore::SQLiteDatabaseTracker::incrementTransactionInProgressCount):
(WebCore::SQLiteDatabaseTracker::decrementTransactionInProgressCount):
(WebCore::SQLiteDatabaseTracker::hasTransactionInProgress):
* platform/text/TextEncodingRegistry.cpp:
(WebCore::buildBaseTextCodecMaps):
(WebCore::newTextCodec):
(WebCore::atomCanonicalTextEncodingName):

Source/WebKit:

* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::traverse):
* Platform/IPC/Connection.cpp:
(IPC::Connection::SyncMessageState::processIncomingMessage):
(IPC::Connection::SyncMessageState::dispatchMessages):
(IPC::Connection::SyncMessageState::dispatchMessagesAndResetDidScheduleDispatchMessagesForConnection):
(IPC::Connection::addWorkQueueMessageReceiver):
(IPC::Connection::removeWorkQueueMessageReceiver):
(IPC::Connection::addThreadMessageReceiver):
(IPC::Connection::removeThreadMessageReceiver):
(IPC::Connection::sendMessage):
(IPC::Connection::waitForMessage):
(IPC::Connection::processIncomingMessage):
(IPC::Connection::installIncomingSyncMessageCallback):
(IPC::Connection::uninstallIncomingSyncMessageCallback):
(IPC::Connection::hasIncomingSyncMessage):
(IPC::Connection::connectionDidClose):
(IPC::Connection::sendOutgoingMessages):
(IPC::Connection::enqueueIncomingMessage):
(IPC::Connection::dispatchMessageToWorkQueueReceiver):
(IPC::Connection::dispatchMessageToThreadReceiver):
(IPC::Connection::dispatchOneIncomingMessage):
(IPC::Connection::dispatchIncomingMessages):
* Shared/BlockingResponseMap.h:
(BlockingResponseMap::didReceiveResponse):
* UIProcess/mac/WKPrintingView.mm:
(-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]):
(prepareDataForPrintingOnSecondaryThread):

Source/WebKitLegacy/mac:

* DOM/DOMInternal.mm:
(getDOMWrapper):
(addDOMWrapper):
(removeDOMWrapper):

Source/WTF:

Remove use of std::lock_guard. This is deprecated in C++17.

1. For particularly low-level usage (like, bmalloc, std::mutex), use std::scoped_lock.
2. For the other purpose, use holdLock.

* benchmarks/ConditionSpeedTest.cpp:
* wtf/CryptographicallyRandomNumber.cpp:
* wtf/HashTable.cpp:
(WTF::HashTableStats::recordCollisionAtCount):
(WTF::HashTableStats::dumpStats):
* wtf/HashTable.h:
(WTF::KeyTraits>::invalidateIterators):
(WTF::addIterator):
(WTF::removeIterator):
* wtf/Language.cpp:
(WTF::userPreferredLanguages):
* wtf/MainThread.cpp:
(WTF::dispatchFunctionsFromMainThread):
(WTF::callOnMainThread):
(WTF::callOnMainAndWait):
* wtf/StackStats.cpp:
(WTF::StackStats::CheckPoint::CheckPoint):
(WTF::StackStats::CheckPoint::~CheckPoint):
(WTF::StackStats::probe):
(WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
(WTF::StackStats::LayoutCheckPoint::~LayoutCheckPoint):
* wtf/WordLock.cpp:
(WTF::WordLock::unlockSlow):
* wtf/cf/LanguageCF.cpp:
(WTF::languagePreferencesDidChange):
(WTF::platformUserPreferredLanguages):
* wtf/text/StringView.cpp:
(WTF::StringView::invalidate):
(WTF::StringView::adoptUnderlyingString):
(WTF::StringView::setUnderlyingString):
* wtf/unicode/icu/CollatorICU.cpp:
(WTF::Collator::Collator):
(WTF::Collator::~Collator):
* wtf/win/LanguageWin.cpp:
(WTF::platformLanguage):

Tools:

Add std::lock_guard lint rule to prevent from using it.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_lock_guard):
(check_style):
(CppChecker):
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_lock_guard):
* TestWebKitAPI/Tests/WTF/Condition.cpp:
* TestWebKitAPI/Tests/WTF/ParkingLot.cpp:
* TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp:
(assertHasObjects):
(assertHasOnlyObjects):
* WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
(WTR::AXThread::dispatch):
(WTR::AXThread::dispatchFunctionsFromAXThread):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
(WTR::AXThread::initializeRunLoop):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257688 268f45cc-cd09-0410-ab3c-d52691b4dbfc

61 files changed:
Source/JavaScriptCore/API/JSVirtualMachine.mm
Source/JavaScriptCore/API/glib/JSCVirtualMachine.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp
Source/JavaScriptCore/heap/MachineStackMarker.cpp
Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp
Source/WTF/ChangeLog
Source/WTF/benchmarks/ConditionSpeedTest.cpp
Source/WTF/wtf/CryptographicallyRandomNumber.cpp
Source/WTF/wtf/HashTable.cpp
Source/WTF/wtf/HashTable.h
Source/WTF/wtf/Language.cpp
Source/WTF/wtf/MainThread.cpp
Source/WTF/wtf/StackStats.cpp
Source/WTF/wtf/WordLock.cpp
Source/WTF/wtf/cf/LanguageCF.cpp
Source/WTF/wtf/text/StringView.cpp
Source/WTF/wtf/unicode/icu/CollatorICU.cpp
Source/WTF/wtf/win/LanguageWin.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp
Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp
Source/WebCore/Modules/webaudio/ConvolverNode.cpp
Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp
Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.cpp
Source/WebCore/Modules/webaudio/OscillatorNode.cpp
Source/WebCore/Modules/webaudio/PannerNode.cpp
Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp
Source/WebCore/Modules/webdatabase/Database.cpp
Source/WebCore/Modules/webdatabase/DatabaseManager.cpp
Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp
Source/WebCore/inspector/agents/WebHeapAgent.cpp
Source/WebCore/page/scrolling/ScrollingThread.cpp
Source/WebCore/page/scrolling/generic/ScrollingThreadGeneric.cpp
Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm
Source/WebCore/platform/audio/ReverbConvolver.cpp
Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/ios/wak/WebCoreThreadRun.cpp
Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm
Source/WebCore/platform/network/cf/LoaderRunLoopCF.cpp
Source/WebCore/platform/sql/SQLiteDatabase.cpp
Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp
Source/WebCore/platform/text/TextEncodingRegistry.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp
Source/WebKit/Platform/IPC/Connection.cpp
Source/WebKit/Shared/BlockingResponseMap.h
Source/WebKit/UIProcess/mac/WKPrintingView.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/DOMInternal.mm
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Mutex.h
Tools/ChangeLog
Tools/Scripts/webkitpy/style/checkers/cpp.py
Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
Tools/TestWebKitAPI/Tests/WTF/Condition.cpp
Tools/TestWebKitAPI/Tests/WTF/ParkingLot.cpp
Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp
Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm

index 0d00829..c4736af 100644 (file)
@@ -70,13 +70,13 @@ static NSMapTable *wrapperCache()
 
 + (void)addWrapper:(JSVirtualMachine *)wrapper forJSContextGroupRef:(JSContextGroupRef)group
 {
-    std::lock_guard<Lock> lock(wrapperCacheMutex);
+    auto locker = holdLock(wrapperCacheMutex);
     NSMapInsert(wrapperCache(), group, (__bridge void*)wrapper);
 }
 
 + (JSVirtualMachine *)wrapperForJSContextGroupRef:(JSContextGroupRef)group
 {
-    std::lock_guard<Lock> lock(wrapperCacheMutex);
+    auto locker = holdLock(wrapperCacheMutex);
     return (__bridge JSVirtualMachine *)NSMapGet(wrapperCache(), group);
 }
 
index c061afe..b23b707 100644 (file)
@@ -57,14 +57,14 @@ static HashMap<JSContextGroupRef, JSCVirtualMachine*>& wrapperMap()
 
 static void addWrapper(JSContextGroupRef group, JSCVirtualMachine* vm)
 {
-    std::lock_guard<Lock> lock(wrapperCacheMutex);
+    auto locker = holdLock(wrapperCacheMutex);
     ASSERT(!wrapperMap().contains(group));
     wrapperMap().set(group, vm);
 }
 
 static void removeWrapper(JSContextGroupRef group)
 {
-    std::lock_guard<Lock> lock(wrapperCacheMutex);
+    auto locker = holdLock(wrapperCacheMutex);
     ASSERT(wrapperMap().contains(group));
     wrapperMap().remove(group);
 }
index 2c0f58e..1b85159 100644 (file)
@@ -1,3 +1,28 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        * API/JSVirtualMachine.mm:
+        (+[JSVMWrapperCache addWrapper:forJSContextGroupRef:]):
+        (+[JSVMWrapperCache wrapperForJSContextGroupRef:]):
+        * API/glib/JSCVirtualMachine.cpp:
+        (addWrapper):
+        (removeWrapper):
+        * heap/HeapSnapshotBuilder.cpp:
+        (JSC::HeapSnapshotBuilder::analyzeNode):
+        (JSC::HeapSnapshotBuilder::analyzeEdge):
+        (JSC::HeapSnapshotBuilder::analyzePropertyNameEdge):
+        (JSC::HeapSnapshotBuilder::analyzeVariableNameEdge):
+        (JSC::HeapSnapshotBuilder::analyzeIndexEdge):
+        (JSC::HeapSnapshotBuilder::setOpaqueRootReachabilityReasonForCell):
+        * heap/MachineStackMarker.cpp:
+        (JSC::MachineThreads::tryCopyOtherThreadStacks):
+        * runtime/JSRunLoopTimer.cpp:
+        (JSC::JSRunLoopTimer::timerDidFire):
+
 2020-02-28  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] BuiltinNames' HashMap should be small
index ce039ba..d5b9ad2 100644 (file)
@@ -88,7 +88,7 @@ void HeapSnapshotBuilder::analyzeNode(JSCell* cell)
     if (previousSnapshotHasNodeForCell(cell, identifier))
         return;
 
-    std::lock_guard<Lock> lock(m_buildingNodeMutex);
+    auto locker = holdLock(m_buildingNodeMutex);
     m_snapshot->appendNode(HeapSnapshotNode(cell, getNextObjectIdentifier()));
 }
 
@@ -101,7 +101,7 @@ void HeapSnapshotBuilder::analyzeEdge(JSCell* from, JSCell* to, SlotVisitor::Roo
     if (from == to)
         return;
 
-    std::lock_guard<Lock> lock(m_buildingEdgeMutex);
+    auto locker = holdLock(m_buildingEdgeMutex);
 
     if (m_snapshotType == SnapshotType::GCDebuggingSnapshot && !from) {
         if (rootMarkReason == SlotVisitor::RootMarkReason::None && m_snapshotType == SnapshotType::GCDebuggingSnapshot)
@@ -120,7 +120,7 @@ void HeapSnapshotBuilder::analyzePropertyNameEdge(JSCell* from, JSCell* to, Uniq
     ASSERT(m_profiler.activeHeapAnalyzer() == this);
     ASSERT(to);
 
-    std::lock_guard<Lock> lock(m_buildingEdgeMutex);
+    auto locker = holdLock(m_buildingEdgeMutex);
 
     m_edges.append(HeapSnapshotEdge(from, to, EdgeType::Property, propertyName));
 }
@@ -130,7 +130,7 @@ void HeapSnapshotBuilder::analyzeVariableNameEdge(JSCell* from, JSCell* to, Uniq
     ASSERT(m_profiler.activeHeapAnalyzer() == this);
     ASSERT(to);
 
-    std::lock_guard<Lock> lock(m_buildingEdgeMutex);
+    auto locker = holdLock(m_buildingEdgeMutex);
 
     m_edges.append(HeapSnapshotEdge(from, to, EdgeType::Variable, variableName));
 }
@@ -140,7 +140,7 @@ void HeapSnapshotBuilder::analyzeIndexEdge(JSCell* from, JSCell* to, uint32_t in
     ASSERT(m_profiler.activeHeapAnalyzer() == this);
     ASSERT(to);
 
-    std::lock_guard<Lock> lock(m_buildingEdgeMutex);
+    auto locker = holdLock(m_buildingEdgeMutex);
 
     m_edges.append(HeapSnapshotEdge(from, to, index));
 }
@@ -150,7 +150,7 @@ void HeapSnapshotBuilder::setOpaqueRootReachabilityReasonForCell(JSCell* cell, c
     if (!reason || !*reason || m_snapshotType != SnapshotType::GCDebuggingSnapshot)
         return;
 
-    std::lock_guard<Lock> lock(m_buildingEdgeMutex);
+    auto locker = holdLock(m_buildingEdgeMutex);
 
     m_rootData.ensure(cell, [] () -> RootData {
         return { };
index ab19c0e..385cec4 100644 (file)
@@ -137,8 +137,8 @@ bool MachineThreads::tryCopyOtherThreadStacks(const AbstractLocker& locker, void
 {
     // Prevent two VMs from suspending each other's threads at the same time,
     // which can cause deadlock: <rdar://problem/20300842>.
-    static Lock mutex;
-    std::lock_guard<Lock> lock(mutex);
+    static Lock suspendLock;
+    auto suspendLocker = holdLock(suspendLock);
 
     *size = 0;
 
index 07b0d49..1355460 100644 (file)
@@ -295,7 +295,7 @@ void JSRunLoopTimer::timerDidFire()
         }
     }
 
-    std::lock_guard<JSLock> lock(m_apiLock.get());
+    auto locker = holdLock(m_apiLock.get());
     RefPtr<VM> vm = m_apiLock->vm();
     if (!vm) {
         // The VM has been destroyed, so we should just give up.
index 9f2c914..d50c37e 100644 (file)
@@ -1,3 +1,51 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        Remove use of std::lock_guard. This is deprecated in C++17.
+
+        1. For particularly low-level usage (like, bmalloc, std::mutex), use std::scoped_lock.
+        2. For the other purpose, use holdLock.
+
+        * benchmarks/ConditionSpeedTest.cpp:
+        * wtf/CryptographicallyRandomNumber.cpp:
+        * wtf/HashTable.cpp:
+        (WTF::HashTableStats::recordCollisionAtCount):
+        (WTF::HashTableStats::dumpStats):
+        * wtf/HashTable.h:
+        (WTF::KeyTraits>::invalidateIterators):
+        (WTF::addIterator):
+        (WTF::removeIterator):
+        * wtf/Language.cpp:
+        (WTF::userPreferredLanguages):
+        * wtf/MainThread.cpp:
+        (WTF::dispatchFunctionsFromMainThread):
+        (WTF::callOnMainThread):
+        (WTF::callOnMainAndWait):
+        * wtf/StackStats.cpp:
+        (WTF::StackStats::CheckPoint::CheckPoint):
+        (WTF::StackStats::CheckPoint::~CheckPoint):
+        (WTF::StackStats::probe):
+        (WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
+        (WTF::StackStats::LayoutCheckPoint::~LayoutCheckPoint):
+        * wtf/WordLock.cpp:
+        (WTF::WordLock::unlockSlow):
+        * wtf/cf/LanguageCF.cpp:
+        (WTF::languagePreferencesDidChange):
+        (WTF::platformUserPreferredLanguages):
+        * wtf/text/StringView.cpp:
+        (WTF::StringView::invalidate):
+        (WTF::StringView::adoptUnderlyingString):
+        (WTF::StringView::setUnderlyingString):
+        * wtf/unicode/icu/CollatorICU.cpp:
+        (WTF::Collator::Collator):
+        (WTF::Collator::~Collator):
+        * wtf/win/LanguageWin.cpp:
+        (WTF::platformLanguage):
+
 2020-02-28  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] BuiltinNames' HashMap should be small
index f59b08d..1c0d5d3 100644 (file)
@@ -118,7 +118,7 @@ void runTest(
                     notify(fullCondition, mustNotify);
 
                     {
-                        std::lock_guard<LockType> locker(receivedLock);
+                        auto locker = holdLock(receivedLock);
                         received.append(result);
                     }
                 }
@@ -152,7 +152,7 @@ void runTest(
         thread->waitForCompletion();
 
     {
-        std::lock_guard<LockType> locker(lock);
+        auto locker = holdLock(lock);
         shouldContinue = false;
     }
     notifyAll(emptyCondition);
index 7ac4e18..afbce89 100644 (file)
@@ -138,7 +138,7 @@ uint32_t ARC4RandomNumberGenerator::getWord()
 
 uint32_t ARC4RandomNumberGenerator::randomNumber()
 {
-    std::lock_guard<Lock> lock(m_mutex);
+    auto locker = holdLock(m_mutex);
 
     m_count -= 4;
     stirIfNeeded();
@@ -147,7 +147,7 @@ uint32_t ARC4RandomNumberGenerator::randomNumber()
 
 void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length)
 {
-    std::lock_guard<Lock> lock(m_mutex);
+    auto locker = holdLock(m_mutex);
 
     unsigned char* result = reinterpret_cast<unsigned char*>(buffer);
     stirIfNeeded();
index 53b4cdb..027c5c4 100644 (file)
@@ -43,7 +43,7 @@ static Lock hashTableStatsMutex;
 
 void HashTableStats::recordCollisionAtCount(unsigned count)
 {
-    std::lock_guard<Lock> lock(hashTableStatsMutex);
+    auto locker = holdLock(hashTableStatsMutex);
 
     if (count > maxCollisions)
         maxCollisions = count;
@@ -53,7 +53,7 @@ void HashTableStats::recordCollisionAtCount(unsigned count)
 
 void HashTableStats::dumpStats()
 {
-    std::lock_guard<Lock> lock(hashTableStatsMutex);
+    auto locker = holdLock(hashTableStatsMutex);
 
     dataLogF("\nWTF::HashTable statistics\n\n");
     dataLogF("%u accesses\n", numAccesses.load());
index 9074782..ceb162d 100644 (file)
@@ -1495,7 +1495,7 @@ DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(HashTable);
     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::invalidateIterators()
     {
-        std::lock_guard<Lock> lock(*m_mutex);
+        auto locker = holdLock(*m_mutex);
         const_iterator* next;
         for (const_iterator* p = m_iterators; p; p = next) {
             next = p->m_next;
@@ -1517,7 +1517,7 @@ DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(HashTable);
         if (!table) {
             it->m_next = 0;
         } else {
-            std::lock_guard<Lock> lock(*table->m_mutex);
+            auto locker = holdLock(*table->m_mutex);
             ASSERT(table->m_iterators != it);
             it->m_next = table->m_iterators;
             table->m_iterators = it;
@@ -1536,7 +1536,7 @@ DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(HashTable);
             ASSERT(!it->m_next);
             ASSERT(!it->m_previous);
         } else {
-            std::lock_guard<Lock> lock(*it->m_table->m_mutex);
+            auto locker = holdLock(*it->m_table->m_mutex);
             if (it->m_next) {
                 ASSERT(it->m_next->m_previous == it);
                 it->m_next->m_previous = it->m_previous;
index 09d0ead..f4cf064 100644 (file)
@@ -103,7 +103,7 @@ static Vector<String> isolatedCopy(const Vector<String>& strings)
 Vector<String> userPreferredLanguages()
 {
     {
-        std::lock_guard<Lock> lock(userPreferredLanguagesMutex);
+        auto locker = holdLock(userPreferredLanguagesMutex);
         Vector<String>& override = preferredLanguagesOverride();
         if (!override.isEmpty())
             return isolatedCopy(override);
index 4994575..60e80d4 100644 (file)
@@ -84,7 +84,7 @@ void dispatchFunctionsFromMainThread()
 
     while (true) {
         {
-            std::lock_guard<Lock> lock(mainThreadFunctionQueueMutex);
+            auto locker = holdLock(mainThreadFunctionQueueMutex);
             if (!functionQueue().size())
                 break;
 
@@ -124,7 +124,7 @@ void callOnMainThread(Function<void()>&& function)
     bool needToSchedule = false;
 
     {
-        std::lock_guard<Lock> lock(mainThreadFunctionQueueMutex);
+        auto locker = holdLock(mainThreadFunctionQueueMutex);
         needToSchedule = functionQueue().size() == 0;
         functionQueue().append(WTFMove(function));
     }
@@ -175,7 +175,7 @@ static void callOnMainAndWait(WTF::Function<void()>&& function, MainStyle mainSt
     auto functionImpl = [&, function = WTFMove(function)] {
         function();
 
-        std::lock_guard<Lock> lock(mutex);
+        auto locker = holdLock(mutex);
         isFinished = true;
         conditionVariable.notifyOne();
     };
index c1c435f..3f1ab52 100644 (file)
@@ -68,7 +68,7 @@ StackStats::PerThreadStats::PerThreadStats()
 
 StackStats::CheckPoint::CheckPoint()
 {
-    std::lock_guard<Lock> lock(StackStats::s_sharedMutex);
+    auto locker = holdLock(StackStats::s_sharedMutex);
     Thread& thread = Thread::current();
     StackStats::PerThreadStats& t = thread.stackStats();
     const StackBounds& stack = thread.stack();
@@ -121,7 +121,7 @@ StackStats::CheckPoint::CheckPoint()
 
 StackStats::CheckPoint::~CheckPoint()
 {
-    std::lock_guard<Lock> lock(StackStats::s_sharedMutex);
+    auto locker = holdLock(StackStats::s_sharedMutex);
     Thread& thread = Thread::current();
     StackStats::PerThreadStats& t = thread.stackStats();
 
@@ -148,7 +148,7 @@ StackStats::CheckPoint::~CheckPoint()
 
 void StackStats::probe()
 {
-    std::lock_guard<Lock> lock(StackStats::s_sharedMutex);
+    auto locker = holdLock(StackStats::s_sharedMutex);
     Thread& thread = Thread::current();
     StackStats::PerThreadStats& t = thread.stackStats();
     const StackBounds& stack = thread.stack();
@@ -203,7 +203,7 @@ StackStats::LayoutCheckPoint::LayoutCheckPoint()
     // probe first, we can avoid re-entering the lock.
     StackStats::probe();
 
-    std::lock_guard<Lock> lock(StackStats::s_sharedMutex);
+    auto locker = holdLock(StackStats::s_sharedMutex);
     Thread& thread = Thread::current();
     StackStats::PerThreadStats& t = thread.stackStats();
     const StackBounds& stack = thread.stack();
@@ -264,7 +264,7 @@ StackStats::LayoutCheckPoint::LayoutCheckPoint()
 
 StackStats::LayoutCheckPoint::~LayoutCheckPoint()
 {
-    std::lock_guard<Lock> lock(StackStats::s_sharedMutex);
+    auto locker = holdLock(StackStats::s_sharedMutex);
 
     // Pop to the previous layout checkpoint:
     StackStats::s_topLayoutCheckPoint = m_prev;
index fb2c78e..45506f9 100644 (file)
@@ -236,7 +236,7 @@ NEVER_INLINE void WordLock::unlockSlow()
     {
         // Be sure to hold the lock across our call to notify_one() because a spurious wakeup could
         // cause the thread at the head of the queue to exit and delete queueHead.
-        std::lock_guard<std::mutex> locker(queueHead->parkingLock);
+        std::scoped_lock<std::mutex> locker(queueHead->parkingLock);
         queueHead->shouldPark = false;
 
         // Doesn't matter if we notify_all() or notify_one() here since the only thread that could be
index 74c1af4..12396da 100644 (file)
@@ -83,7 +83,7 @@ static String httpStyleLanguageCode(CFStringRef language)
 static void languagePreferencesDidChange(CFNotificationCenterRef, void*, CFStringRef, const void*, CFDictionaryRef)
 {
     {
-        std::lock_guard<Lock> lock(preferredLanguagesMutex);
+        auto locker = holdLock(preferredLanguagesMutex);
         preferredLanguages().clear();
     }
     
@@ -100,7 +100,7 @@ Vector<String> platformUserPreferredLanguages()
     });
 #endif
 
-    std::lock_guard<Lock> lock(preferredLanguagesMutex);
+    auto locker = holdLock(preferredLanguagesMutex);
     Vector<String>& userPreferredLanguages = preferredLanguages();
 
     if (userPreferredLanguages.isEmpty()) {
index c798555..8d4798a 100644 (file)
@@ -308,7 +308,7 @@ void StringView::invalidate(const StringImpl& stringToBeDestroyed)
 {
     UnderlyingString* underlyingString;
     {
-        std::lock_guard<Lock> lock(underlyingStringsMutex);
+        auto locker = holdLock(underlyingStringsMutex);
         underlyingString = underlyingStrings().take(&stringToBeDestroyed);
         if (!underlyingString)
             return;
@@ -325,7 +325,7 @@ bool StringView::underlyingStringIsValid() const
 void StringView::adoptUnderlyingString(UnderlyingString* underlyingString)
 {
     if (m_underlyingString) {
-        std::lock_guard<Lock> lock(underlyingStringsMutex);
+        auto locker = holdLock(underlyingStringsMutex);
         if (!--m_underlyingString->refCount) {
             if (m_underlyingString->isValid) {
                 underlyingStrings().remove(&m_underlyingString->string);
@@ -342,7 +342,7 @@ void StringView::setUnderlyingString(const StringImpl* string)
     if (!string)
         underlyingString = nullptr;
     else {
-        std::lock_guard<Lock> lock(underlyingStringsMutex);
+        auto locker = holdLock(underlyingStringsMutex);
         auto result = underlyingStrings().add(string, nullptr);
         if (result.isNewEntry)
             result.iterator->value = new UnderlyingString(*string);
index d0f20b9..6766073 100644 (file)
@@ -106,7 +106,7 @@ Collator::Collator(const char* locale, bool shouldSortLowercaseFirst)
     UErrorCode status = U_ZERO_ERROR;
 
     {
-        std::lock_guard<Lock> lock(cachedCollatorMutex);
+        auto locker = holdLock(cachedCollatorMutex);
         if (cachedCollator && localesMatch(cachedCollatorLocale, locale) && cachedCollatorShouldSortLowercaseFirst == shouldSortLowercaseFirst) {
             m_collator = cachedCollator;
             m_locale = cachedCollatorLocale;
@@ -136,7 +136,7 @@ Collator::Collator(const char* locale, bool shouldSortLowercaseFirst)
 
 Collator::~Collator()
 {
-    std::lock_guard<Lock> lock(cachedCollatorMutex);
+    auto locker = holdLock(cachedCollatorMutex);
     if (cachedCollator) {
         ucol_close(cachedCollator);
         fastFree(cachedCollatorLocale);
index fc1fc52..3087597 100644 (file)
@@ -57,7 +57,7 @@ static String localeInfo(LCTYPE localeType, const String& fallback)
 
 static String platformLanguage()
 {
-    std::lock_guard<Lock> lock(platformLanguageMutex);
+    auto locker = holdLock(platformLanguageMutex);
 
     static String computedDefaultLanguage;
     if (!computedDefaultLanguage.isEmpty())
index 0f35dec..a8a805b 100644 (file)
@@ -1,3 +1,87 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        * Modules/webaudio/AudioBufferSourceNode.cpp:
+        (WebCore::AudioBufferSourceNode::setBuffer):
+        * Modules/webaudio/AudioParamTimeline.cpp:
+        (WebCore::AudioParamTimeline::insertEvent):
+        (WebCore::AudioParamTimeline::cancelScheduledValues):
+        * Modules/webaudio/ConvolverNode.cpp:
+        (WebCore::ConvolverNode::reset):
+        (WebCore::ConvolverNode::setBuffer):
+        * Modules/webaudio/MediaElementAudioSourceNode.cpp:
+        (WebCore::MediaElementAudioSourceNode::setFormat):
+        * Modules/webaudio/MediaStreamAudioSourceNode.cpp:
+        (WebCore::MediaStreamAudioSourceNode::setFormat):
+        * Modules/webaudio/OscillatorNode.cpp:
+        (WebCore::OscillatorNode::setPeriodicWave):
+        * Modules/webaudio/PannerNode.cpp:
+        (WebCore::PannerNode::setPanningModel):
+        * Modules/webaudio/WaveShaperProcessor.cpp:
+        (WebCore::WaveShaperProcessor::setCurve):
+        (WebCore::WaveShaperProcessor::setOversample):
+        * Modules/webdatabase/Database.cpp:
+        (WebCore::Database::Database):
+        (WebCore::Database::performOpenAndVerify):
+        (WebCore::Database::closeDatabase):
+        (WebCore::Database::getCachedVersion const):
+        (WebCore::Database::setCachedVersion):
+        * Modules/webdatabase/DatabaseManager.cpp:
+        (WebCore::DatabaseManager::addProposedDatabase):
+        (WebCore::DatabaseManager::removeProposedDatabase):
+        (WebCore::DatabaseManager::fullPathForDatabase):
+        (WebCore::DatabaseManager::detailsForNameAndOrigin):
+        * crypto/CryptoAlgorithmRegistry.cpp:
+        (WebCore::CryptoAlgorithmRegistry::identifier):
+        (WebCore::CryptoAlgorithmRegistry::name):
+        (WebCore::CryptoAlgorithmRegistry::create):
+        (WebCore::CryptoAlgorithmRegistry::registerAlgorithm):
+        * inspector/agents/WebHeapAgent.cpp:
+        (WebCore::SendGarbageCollectionEventsTask::addGarbageCollection):
+        (WebCore::SendGarbageCollectionEventsTask::reset):
+        (WebCore::SendGarbageCollectionEventsTask::timerFired):
+        * page/scrolling/ScrollingThread.cpp:
+        (WebCore::ScrollingThread::dispatch):
+        (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):
+        * page/scrolling/generic/ScrollingThreadGeneric.cpp:
+        (WebCore::ScrollingThread::initializeRunLoop):
+        * page/scrolling/mac/ScrollingThreadMac.mm:
+        (WebCore::ScrollingThread::initializeRunLoop):
+        * platform/audio/ReverbConvolver.cpp:
+        (WebCore::ReverbConvolver::~ReverbConvolver):
+        * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
+        (WebCore::AudioSourceProviderAVFObjC::~AudioSourceProviderAVFObjC):
+        (WebCore::AudioSourceProviderAVFObjC::finalizeCallback):
+        (WebCore::AudioSourceProviderAVFObjC::prepareCallback):
+        (WebCore::AudioSourceProviderAVFObjC::unprepareCallback):
+        (WebCore::AudioSourceProviderAVFObjC::processCallback):
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontDatabase::collectionForFamily):
+        (WebCore::FontDatabase::clear):
+        * platform/ios/wak/WebCoreThreadRun.cpp:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
+        (WebCore::WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC):
+        (WebCore::WebAudioSourceProviderAVFObjC::prepare):
+        (WebCore::WebAudioSourceProviderAVFObjC::unprepare):
+        * platform/network/cf/LoaderRunLoopCF.cpp:
+        (WebCore::loaderRunLoop):
+        * platform/sql/SQLiteDatabase.cpp:
+        (WebCore::SQLiteDatabase::setIsDatabaseOpeningForbidden):
+        (WebCore::SQLiteDatabase::open):
+        * platform/sql/SQLiteDatabaseTracker.cpp:
+        (WebCore::SQLiteDatabaseTracker::setClient):
+        (WebCore::SQLiteDatabaseTracker::incrementTransactionInProgressCount):
+        (WebCore::SQLiteDatabaseTracker::decrementTransactionInProgressCount):
+        (WebCore::SQLiteDatabaseTracker::hasTransactionInProgress):
+        * platform/text/TextEncodingRegistry.cpp:
+        (WebCore::buildBaseTextCodecMaps):
+        (WebCore::newTextCodec):
+        (WebCore::atomCanonicalTextEncodingName):
+
 2020-02-29  Per Arne Vollan  <pvollan@apple.com>
 
         [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
index 3306b9c..c3661de 100644 (file)
@@ -416,7 +416,7 @@ void AudioBufferSourceNode::setBuffer(RefPtr<AudioBuffer>&& buffer)
     AudioContext::AutoLocker contextLocker(context());
     
     // This synchronizes with process().
-    std::lock_guard<Lock> lock(m_processMutex);
+    auto locker = holdLock(m_processMutex);
     
     if (buffer) {
         // Do any necesssary re-configuration to the buffer's number of channels.
index fdc1d3c..2b59570 100644 (file)
@@ -80,7 +80,7 @@ void AudioParamTimeline::insertEvent(const ParamEvent& event)
     if (!isValid)
         return;
         
-    std::lock_guard<Lock> lock(m_eventsMutex);
+    auto locker = holdLock(m_eventsMutex);
     
     unsigned i = 0;
     float insertTime = event.time();
@@ -102,7 +102,7 @@ void AudioParamTimeline::insertEvent(const ParamEvent& event)
 
 void AudioParamTimeline::cancelScheduledValues(float startTime)
 {
-    std::lock_guard<Lock> lock(m_eventsMutex);
+    auto locker = holdLock(m_eventsMutex);
 
     // Remove all events starting at startTime.
     for (unsigned i = 0; i < m_events.size(); ++i) {
index e36677c..cc972f1 100644 (file)
@@ -94,7 +94,7 @@ void ConvolverNode::process(size_t framesToProcess)
 
 void ConvolverNode::reset()
 {
-    std::lock_guard<Lock> lock(m_processMutex);
+    auto locker = holdLock(m_processMutex);
     if (m_reverb)
         m_reverb->reset();
 }
@@ -150,7 +150,7 @@ ExceptionOr<void> ConvolverNode::setBuffer(AudioBuffer* buffer)
 
     {
         // Synchronize with process().
-        std::lock_guard<Lock> lock(m_processMutex);
+        auto locker = holdLock(m_processMutex);
         m_reverb = WTFMove(reverb);
         m_buffer = buffer;
     }
index 912e6eb..0e5981f 100644 (file)
@@ -85,7 +85,7 @@ void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourc
         m_sourceSampleRate = sourceSampleRate;
 
         // Synchronize with process().
-        std::lock_guard<MediaElementAudioSourceNode> lock(*this);
+        auto locker = holdLock(*this);
 
         if (sourceSampleRate != sampleRate()) {
             double scaleFactor = sourceSampleRate / sampleRate();
index 7ba59bf..1b4fb6d 100644 (file)
@@ -84,7 +84,7 @@ void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
     }
 
     // Synchronize with process().
-    std::lock_guard<Lock> lock(m_processMutex);
+    auto locker = holdLock(m_processMutex);
 
     m_sourceNumberOfChannels = numberOfChannels;
     m_sourceSampleRate = sourceSampleRate;
index a99ceaa..9560053 100644 (file)
@@ -306,7 +306,7 @@ void OscillatorNode::setPeriodicWave(PeriodicWave* periodicWave)
     ASSERT(isMainThread());
     
     // This synchronizes with process().
-    std::lock_guard<Lock> lock(m_processMutex);
+    auto locker = holdLock(m_processMutex);
     m_periodicWave = periodicWave;
     m_type = Type::Custom;
 }
index 9242f88..508736b 100644 (file)
@@ -182,7 +182,7 @@ void PannerNode::setPanningModel(PanningModelType model)
 {
     if (!m_panner.get() || model != m_panningModel) {
         // This synchronizes with process().
-        std::lock_guard<Lock> lock(m_pannerMutex);
+        auto locker = holdLock(m_pannerMutex);
 
         m_panner = Panner::create(model, sampleRate(), m_hrtfDatabaseLoader.get());
         m_panningModel = model;
index bfe5e0e..7756499 100644 (file)
@@ -52,7 +52,7 @@ std::unique_ptr<AudioDSPKernel> WaveShaperProcessor::createKernel()
 void WaveShaperProcessor::setCurve(Float32Array* curve)
 {
     // This synchronizes with process().
-    std::lock_guard<Lock> lock(m_processMutex);
+    auto locker = holdLock(m_processMutex);
 
     m_curve = curve;
 }
@@ -60,7 +60,7 @@ void WaveShaperProcessor::setCurve(Float32Array* curve)
 void WaveShaperProcessor::setOversample(OverSampleType oversample)
 {
     // This synchronizes with process().
-    std::lock_guard<Lock> lock(m_processMutex);
+    auto locker = holdLock(m_processMutex);
 
     m_oversample = oversample;
 
index 218b0c4..ad3952a 100644 (file)
@@ -206,7 +206,7 @@ Database::Database(DatabaseContext& context, const String& name, const String& e
     , m_databaseAuthorizer(DatabaseAuthorizer::create(unqualifiedInfoTableName))
 {
     {
-        std::lock_guard<Lock> locker(guidMutex);
+        auto locker = holdLock(guidMutex);
 
         m_guid = guidForOriginAndName(securityOrigin().securityOrigin()->toString(), name);
         guidToDatabaseMap().ensure(m_guid, [] {
@@ -353,7 +353,7 @@ ExceptionOr<void> Database::performOpenAndVerify(bool shouldSetVersionInNewDatab
 
     String currentVersion;
     {
-        std::lock_guard<Lock> locker(guidMutex);
+        auto locker = holdLock(guidMutex);
 
         auto entry = guidToVersionMap().find(m_guid);
         if (entry != guidToVersionMap().end()) {
@@ -442,7 +442,7 @@ void Database::closeDatabase()
     DatabaseTracker::singleton().removeOpenDatabase(*this);
 
     {
-        std::lock_guard<Lock> locker(guidMutex);
+        auto locker = holdLock(guidMutex);
 
         auto it = guidToDatabaseMap().find(m_guid);
         ASSERT(it != guidToDatabaseMap().end());
@@ -500,14 +500,14 @@ void Database::setExpectedVersion(const String& version)
 
 String Database::getCachedVersion() const
 {
-    std::lock_guard<Lock> locker(guidMutex);
+    auto locker = holdLock(guidMutex);
 
     return guidToVersionMap().get(m_guid).isolatedCopy();
 }
 
 void Database::setCachedVersion(const String& actualVersion)
 {
-    std::lock_guard<Lock> locker(guidMutex);
+    auto locker = holdLock(guidMutex);
 
     updateGUIDVersionMap(m_guid, actualVersion);
 }
index 716f507..5ef6687 100644 (file)
@@ -181,13 +181,13 @@ ExceptionOr<Ref<Database>> DatabaseManager::tryToOpenDatabaseBackend(Document& d
 
 void DatabaseManager::addProposedDatabase(ProposedDatabase& database)
 {
-    std::lock_guard<Lock> lock { m_proposedDatabasesMutex };
+    auto locker = holdLock(m_proposedDatabasesMutex);
     m_proposedDatabases.add(&database);
 }
 
 void DatabaseManager::removeProposedDatabase(ProposedDatabase& database)
 {
-    std::lock_guard<Lock> lock { m_proposedDatabasesMutex };
+    auto locker = holdLock(m_proposedDatabasesMutex);
     m_proposedDatabases.remove(&database);
 }
 
@@ -237,7 +237,7 @@ void DatabaseManager::stopDatabases(Document& document, DatabaseTaskSynchronizer
 String DatabaseManager::fullPathForDatabase(SecurityOrigin& origin, const String& name, bool createIfDoesNotExist)
 {
     {
-        std::lock_guard<Lock> lock { m_proposedDatabasesMutex };
+        auto locker = holdLock(m_proposedDatabasesMutex);
         for (auto* proposedDatabase : m_proposedDatabases) {
             if (proposedDatabase->details().name() == name && proposedDatabase->origin().equal(&origin))
                 return String();
@@ -249,7 +249,7 @@ String DatabaseManager::fullPathForDatabase(SecurityOrigin& origin, const String
 DatabaseDetails DatabaseManager::detailsForNameAndOrigin(const String& name, SecurityOrigin& origin)
 {
     {
-        std::lock_guard<Lock> lock { m_proposedDatabasesMutex };
+        auto locker = holdLock(m_proposedDatabasesMutex);
         for (auto* proposedDatabase : m_proposedDatabases) {
             if (proposedDatabase->details().name() == name && proposedDatabase->origin().equal(&origin)) {
                 ASSERT(&proposedDatabase->details().thread() == &Thread::current() || isMainThread());
index 7a4801a..22f277a 100644 (file)
@@ -52,7 +52,7 @@ Optional<CryptoAlgorithmIdentifier> CryptoAlgorithmRegistry::identifier(const St
     if (name.isEmpty())
         return WTF::nullopt;
 
-    std::lock_guard<Lock> lock(registryMutex);
+    auto locker = holdLock(registryMutex);
 
     // FIXME: How is it helpful to call isolatedCopy on the argument to find?
     auto identifier = m_identifiers.find(name.isolatedCopy());
@@ -64,7 +64,7 @@ Optional<CryptoAlgorithmIdentifier> CryptoAlgorithmRegistry::identifier(const St
 
 String CryptoAlgorithmRegistry::name(CryptoAlgorithmIdentifier identifier)
 {
-    std::lock_guard<Lock> lock(registryMutex);
+    auto locker = holdLock(registryMutex);
 
     auto contructor = m_constructors.find(static_cast<unsigned>(identifier));
     if (contructor == m_constructors.end())
@@ -75,7 +75,7 @@ String CryptoAlgorithmRegistry::name(CryptoAlgorithmIdentifier identifier)
 
 RefPtr<CryptoAlgorithm> CryptoAlgorithmRegistry::create(CryptoAlgorithmIdentifier identifier)
 {
-    std::lock_guard<Lock> lock(registryMutex);
+    auto locker = holdLock(registryMutex);
 
     auto contructor = m_constructors.find(static_cast<unsigned>(identifier));
     if (contructor == m_constructors.end())
@@ -86,7 +86,7 @@ RefPtr<CryptoAlgorithm> CryptoAlgorithmRegistry::create(CryptoAlgorithmIdentifie
 
 void CryptoAlgorithmRegistry::registerAlgorithm(const String& name, CryptoAlgorithmIdentifier identifier, CryptoAlgorithmConstructor constructor)
 {
-    std::lock_guard<Lock> lock(registryMutex);
+    auto locker = holdLock(registryMutex);
 
     ASSERT(!m_identifiers.contains(name));
     ASSERT(!m_constructors.contains(static_cast<unsigned>(identifier)));
index 3cbfb83..acf3c9f 100644 (file)
@@ -64,7 +64,7 @@ SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask(WebHeapAgent& a
 void SendGarbageCollectionEventsTask::addGarbageCollection(GarbageCollectionData&& collection)
 {
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         m_collections.append(WTFMove(collection));
     }
 
@@ -75,7 +75,7 @@ void SendGarbageCollectionEventsTask::addGarbageCollection(GarbageCollectionData
 void SendGarbageCollectionEventsTask::reset()
 {
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         m_collections.clear();
     }
 
@@ -87,7 +87,7 @@ void SendGarbageCollectionEventsTask::timerFired()
     Vector<GarbageCollectionData> collectionsToSend;
 
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         m_collections.swap(collectionsToSend);
     }
 
index b147ecf..92a6086 100644 (file)
@@ -49,7 +49,7 @@ void ScrollingThread::dispatch(Function<void ()>&& function)
     scrollingThread.createThreadIfNeeded();
 
     {
-        std::lock_guard<Lock> lock(scrollingThread.m_functionsMutex);
+        auto locker = holdLock(scrollingThread.m_functionsMutex);
         scrollingThread.m_functions.append(WTFMove(function));
     }
 
@@ -96,7 +96,7 @@ void ScrollingThread::dispatchFunctionsFromScrollingThread()
     Vector<Function<void ()>> functions;
     
     {
-        std::lock_guard<Lock> lock(m_functionsMutex);
+        auto locker = holdLock(m_functionsMutex);
         functions = WTFMove(m_functions);
     }
 
index f699e0e..8a4e71b 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 void ScrollingThread::initializeRunLoop()
 {
     {
-        std::lock_guard<Lock> lock(m_initializeRunLoopMutex);
+        auto locker = holdLock(m_initializeRunLoopMutex);
         m_runLoop = &RunLoop::current();
         m_initializeRunLoopConditionVariable.notifyAll();
     }
index 6d2cda0..f259d66 100644 (file)
@@ -36,7 +36,7 @@ void ScrollingThread::initializeRunLoop()
 {
     // Initialize the run loop.
     {
-        std::lock_guard<Lock> lock(m_initializeRunLoopMutex);
+        auto locker = holdLock(m_initializeRunLoopMutex);
 
         m_threadRunLoop = CFRunLoopGetCurrent();
 
index a12f165..9c3f105 100644 (file)
@@ -135,7 +135,7 @@ ReverbConvolver::~ReverbConvolver()
 
         // Wake up thread so it can return
         {
-            std::lock_guard<Lock> lock(m_backgroundThreadMutex);
+            auto locker = holdLock(m_backgroundThreadMutex);
             m_moreInputBuffered = true;
             m_backgroundThreadConditionVariable.notifyOne();
         }
index 6b3c922..ed80c47 100644 (file)
@@ -88,7 +88,7 @@ AudioSourceProviderAVFObjC::~AudioSourceProviderAVFObjC()
 {
     setClient(nullptr);
     if (m_tapStorage) {
-        std::lock_guard<Lock> lock(m_tapStorage->mutex);
+        auto locker = holdLock(m_tapStorage->mutex);
         m_tapStorage->_this = nullptr;
     }
 
@@ -254,7 +254,7 @@ void AudioSourceProviderAVFObjC::finalizeCallback(MTAudioProcessingTapRef tap)
     TapStorage* tapStorage = static_cast<TapStorage*>(MTAudioProcessingTapGetStorage(tap));
 
     {
-        std::lock_guard<Lock> lock(tapStorage->mutex);
+        auto locker = holdLock(tapStorage->mutex);
         if (tapStorage->_this)
             tapStorage->_this->finalize();
     }
@@ -266,7 +266,7 @@ void AudioSourceProviderAVFObjC::prepareCallback(MTAudioProcessingTapRef tap, CM
     ASSERT(tap);
     TapStorage* tapStorage = static_cast<TapStorage*>(MTAudioProcessingTapGetStorage(tap));
 
-    std::lock_guard<Lock> lock(tapStorage->mutex);
+    auto locker = holdLock(tapStorage->mutex);
 
     if (tapStorage->_this)
         tapStorage->_this->prepare(maxFrames, processingFormat);
@@ -277,7 +277,7 @@ void AudioSourceProviderAVFObjC::unprepareCallback(MTAudioProcessingTapRef tap)
     ASSERT(tap);
     TapStorage* tapStorage = static_cast<TapStorage*>(MTAudioProcessingTapGetStorage(tap));
 
-    std::lock_guard<Lock> lock(tapStorage->mutex);
+    auto locker = holdLock(tapStorage->mutex);
 
     if (tapStorage->_this)
         tapStorage->_this->unprepare();
@@ -288,7 +288,7 @@ void AudioSourceProviderAVFObjC::processCallback(MTAudioProcessingTapRef tap, CM
     ASSERT(tap);
     TapStorage* tapStorage = static_cast<TapStorage*>(MTAudioProcessingTapGetStorage(tap));
 
-    std::lock_guard<Lock> lock(tapStorage->mutex);
+    auto locker = holdLock(tapStorage->mutex);
 
     if (tapStorage->_this)
         tapStorage->_this->process(tap, numberFrames, flags, bufferListInOut, numberFramesOut, flagsOut);
index 0c91e33..49b0b71 100644 (file)
@@ -934,7 +934,7 @@ public:
     {
         auto folded = FontCascadeDescription::foldedFamilyName(familyName);
         {
-            std::lock_guard<Lock> locker(m_familyNameToFontDescriptorsLock);
+            auto locker = holdLock(m_familyNameToFontDescriptorsLock);
             auto it = m_familyNameToFontDescriptors.find(folded);
             if (it != m_familyNameToFontDescriptors.end())
                 return it->value;
@@ -960,7 +960,7 @@ public:
             return InstalledFontFamily();
         }();
 
-        std::lock_guard<Lock> locker(m_familyNameToFontDescriptorsLock);
+        auto locker = holdLock(m_familyNameToFontDescriptorsLock);
         return m_familyNameToFontDescriptors.add(folded.isolatedCopy(), WTFMove(installedFontFamily)).iterator->value;
     }
 
@@ -984,7 +984,7 @@ public:
     void clear()
     {
         {
-            std::lock_guard<Lock> locker(m_familyNameToFontDescriptorsLock);
+            auto locker = holdLock(m_familyNameToFontDescriptorsLock);
             m_familyNameToFontDescriptors.clear();
         }
         m_postScriptNameToFontDescriptors.clear();
index 8ef1657..efa8464 100644 (file)
@@ -52,7 +52,7 @@ public:
 
     void setCompleted()
     {
-        std::lock_guard<Lock> lock(m_stateMutex);
+        auto locker = holdLock(m_stateMutex);
 
         ASSERT(!m_completed);
         m_completed = true;
@@ -124,7 +124,7 @@ static void HandleRunSource(void *info)
 
     WebThreadRunQueue queueCopy;
     {
-        std::lock_guard<Lock> lock(runQueueMutex);
+        auto locker = holdLock(runQueueMutex);
         queueCopy = *runQueue;
         runQueue->clear();
     }
@@ -148,7 +148,7 @@ static void _WebThreadRun(void (^block)(void), bool synchronous)
         state = new WebThreadBlockState;
 
     {
-        std::lock_guard<Lock> lock(runQueueMutex);
+        auto locker = holdLock(runQueueMutex);
         runQueue->append(WebThreadBlock(block, state));
     }
 
index ad862eb..ae902d1 100644 (file)
@@ -59,7 +59,7 @@ WebAudioSourceProviderAVFObjC::WebAudioSourceProviderAVFObjC(MediaStreamTrackPri
 
 WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC()
 {
-    std::lock_guard<Lock> lock(m_mutex);
+    auto locker = holdLock(m_mutex);
 
     if (m_connected && m_captureSource)
         m_captureSource->removeObserver(*this);
@@ -122,7 +122,7 @@ void WebAudioSourceProviderAVFObjC::setClient(AudioSourceProviderClient* client)
 
 void WebAudioSourceProviderAVFObjC::prepare(const AudioStreamBasicDescription& format)
 {
-    std::lock_guard<Lock> lock(m_mutex);
+    auto locker = holdLock(m_mutex);
 
     LOG(Media, "WebAudioSourceProviderAVFObjC::prepare(%p)", this);
 
@@ -153,7 +153,7 @@ void WebAudioSourceProviderAVFObjC::prepare(const AudioStreamBasicDescription& f
 
 void WebAudioSourceProviderAVFObjC::unprepare()
 {
-    std::lock_guard<Lock> lock(m_mutex);
+    auto locker = holdLock(m_mutex);
 
     m_inputDescription = WTF::nullopt;
     m_outputDescription = WTF::nullopt;
index f633fed..5ea448f 100644 (file)
@@ -57,7 +57,7 @@ CFRunLoopRef loaderRunLoop()
     if (!loaderRunLoopObject) {
         Thread::create("WebCore: CFNetwork Loader", [] {
             {
-                std::lock_guard<Lock> lock(loaderRunLoopMutex);
+                auto locker = holdLock(loaderRunLoopMutex);
 
                 loaderRunLoopObject = CFRunLoopGetCurrent();
 
index c41a239..50d75fc 100644 (file)
@@ -76,7 +76,7 @@ static Lock isDatabaseOpeningForbiddenMutex;
 
 void SQLiteDatabase::setIsDatabaseOpeningForbidden(bool isForbidden)
 {
-    std::lock_guard<Lock> lock(isDatabaseOpeningForbiddenMutex);
+    auto locker = holdLock(isDatabaseOpeningForbiddenMutex);
     isDatabaseOpeningForbidden = isForbidden;
 }
 
@@ -94,7 +94,7 @@ bool SQLiteDatabase::open(const String& filename, OpenMode openMode)
     close();
 
     {
-        std::lock_guard<Lock> lock(isDatabaseOpeningForbiddenMutex);
+        auto locker = holdLock(isDatabaseOpeningForbiddenMutex);
         if (isDatabaseOpeningForbidden) {
             m_openErrorMessage = "opening database is forbidden";
             return false;
index 4af2907..6a28e19 100644 (file)
@@ -40,13 +40,13 @@ static Lock transactionInProgressMutex;
 
 void setClient(SQLiteDatabaseTrackerClient* client)
 {
-    std::lock_guard<Lock> lock(transactionInProgressMutex);
+    auto locker = holdLock(transactionInProgressMutex);
     s_staticSQLiteDatabaseTrackerClient = client;
 }
 
 void incrementTransactionInProgressCount()
 {
-    std::lock_guard<Lock> lock(transactionInProgressMutex);
+    auto locker = holdLock(transactionInProgressMutex);
     if (!s_staticSQLiteDatabaseTrackerClient)
         return;
 
@@ -57,7 +57,7 @@ void incrementTransactionInProgressCount()
 
 void decrementTransactionInProgressCount()
 {
-    std::lock_guard<Lock> lock(transactionInProgressMutex);
+    auto locker = holdLock(transactionInProgressMutex);
     if (!s_staticSQLiteDatabaseTrackerClient)
         return;
 
@@ -70,7 +70,7 @@ void decrementTransactionInProgressCount()
 
 bool hasTransactionInProgress()
 {
-    std::lock_guard<Lock> lock(transactionInProgressMutex);
+    auto locker = holdLock(transactionInProgressMutex);
     return !s_staticSQLiteDatabaseTrackerClient || s_transactionInProgressCounter > 0;
 }
 
index c9e150e..2a7850f 100644 (file)
@@ -155,7 +155,7 @@ static void pruneBlacklistedCodecs()
     }
 }
 
-static void buildBaseTextCodecMaps(const std::lock_guard<Lock>&)
+static void buildBaseTextCodecMaps(const AbstractLocker&)
 {
     ASSERT(!textCodecMap);
     ASSERT(!textEncodingNameMap);
@@ -243,7 +243,7 @@ static void extendTextCodecMaps()
 
 std::unique_ptr<TextCodec> newTextCodec(const TextEncoding& encoding)
 {
-    std::lock_guard<Lock> lock(encodingRegistryMutex);
+    auto locker = holdLock(encodingRegistryMutex);
 
     ASSERT(textCodecMap);
     auto result = textCodecMap->find(encoding.name());
@@ -256,10 +256,10 @@ const char* atomCanonicalTextEncodingName(const char* name)
     if (!name || !name[0])
         return nullptr;
 
-    std::lock_guard<Lock> lock(encodingRegistryMutex);
+    auto locker = holdLock(encodingRegistryMutex);
 
     if (!textEncodingNameMap)
-        buildBaseTextCodecMaps(lock);
+        buildBaseTextCodecMaps(locker);
 
     if (const char* atomName = textEncodingNameMap->get(name))
         return atomName;
index fb40ef8..1b1d1d5 100644 (file)
@@ -1,3 +1,39 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::traverse):
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::SyncMessageState::processIncomingMessage):
+        (IPC::Connection::SyncMessageState::dispatchMessages):
+        (IPC::Connection::SyncMessageState::dispatchMessagesAndResetDidScheduleDispatchMessagesForConnection):
+        (IPC::Connection::addWorkQueueMessageReceiver):
+        (IPC::Connection::removeWorkQueueMessageReceiver):
+        (IPC::Connection::addThreadMessageReceiver):
+        (IPC::Connection::removeThreadMessageReceiver):
+        (IPC::Connection::sendMessage):
+        (IPC::Connection::waitForMessage):
+        (IPC::Connection::processIncomingMessage):
+        (IPC::Connection::installIncomingSyncMessageCallback):
+        (IPC::Connection::uninstallIncomingSyncMessageCallback):
+        (IPC::Connection::hasIncomingSyncMessage):
+        (IPC::Connection::connectionDidClose):
+        (IPC::Connection::sendOutgoingMessages):
+        (IPC::Connection::enqueueIncomingMessage):
+        (IPC::Connection::dispatchMessageToWorkQueueReceiver):
+        (IPC::Connection::dispatchMessageToThreadReceiver):
+        (IPC::Connection::dispatchOneIncomingMessage):
+        (IPC::Connection::dispatchIncomingMessages):
+        * Shared/BlockingResponseMap.h:
+        (BlockingResponseMap::didReceiveResponse):
+        * UIProcess/mac/WKPrintingView.mm:
+        (-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]):
+        (prepareDataForPrintingOnSecondaryThread):
+
 2020-02-29  Per Arne Vollan  <pvollan@apple.com>
 
         [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
index ab7a035..cb977f8 100644 (file)
@@ -962,7 +962,7 @@ void Storage::traverse(const String& type, OptionSet<TraverseFlag> flags, Traver
                     traverseOperation.handler(&record, info);
                 }
 
-                std::lock_guard<Lock> lock(traverseOperation.activeMutex);
+                auto locker = holdLock(traverseOperation.activeMutex);
                 --traverseOperation.activeCount;
                 traverseOperation.activeCondition.notifyOne();
             });
index 3ff418a..d0b640d 100644 (file)
@@ -149,7 +149,7 @@ bool Connection::SyncMessageState::processIncomingMessage(Connection& connection
 
     bool shouldDispatch;
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         shouldDispatch = m_didScheduleDispatchMessagesWorkSet.add(&connection).isNewEntry;
         m_messagesToDispatchWhileWaitingForSyncReply.append(ConnectionAndIncomingMessage { connection, WTFMove(message) });
     }
@@ -171,7 +171,7 @@ void Connection::SyncMessageState::dispatchMessages()
 
     Vector<ConnectionAndIncomingMessage> messagesToDispatchWhileWaitingForSyncReply;
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         m_messagesToDispatchWhileWaitingForSyncReply.swap(messagesToDispatchWhileWaitingForSyncReply);
     }
 
@@ -185,7 +185,7 @@ void Connection::SyncMessageState::dispatchMessagesAndResetDidScheduleDispatchMe
 
     Vector<ConnectionAndIncomingMessage> messagesToDispatchWhileWaitingForSyncReply;
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         ASSERT(m_didScheduleDispatchMessagesWorkSet.contains(&connection));
         m_didScheduleDispatchMessagesWorkSet.remove(&connection);
         m_messagesToDispatchWhileWaitingForSyncReply.swap(messagesToDispatchWhileWaitingForSyncReply);
@@ -200,7 +200,7 @@ void Connection::SyncMessageState::dispatchMessagesAndResetDidScheduleDispatchMe
     }
 
     if (!messagesToPutBack.isEmpty()) {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         messagesToPutBack.appendVector(WTFMove(m_messagesToDispatchWhileWaitingForSyncReply));
         m_messagesToDispatchWhileWaitingForSyncReply = WTFMove(messagesToPutBack);
     }
@@ -319,7 +319,7 @@ void Connection::addWorkQueueMessageReceiver(StringReference messageReceiverName
 {
     ASSERT(RunLoop::isMain());
 
-    std::lock_guard<Lock> lock(m_workQueueMessageReceiversMutex);
+    auto locker = holdLock(m_workQueueMessageReceiversMutex);
     ASSERT(!m_workQueueMessageReceivers.contains(messageReceiverName));
 
     m_workQueueMessageReceivers.add(messageReceiverName, std::make_pair(&workQueue, workQueueMessageReceiver));
@@ -329,7 +329,7 @@ void Connection::removeWorkQueueMessageReceiver(StringReference messageReceiverN
 {
     ASSERT(RunLoop::isMain());
 
-    std::lock_guard<Lock> lock(m_workQueueMessageReceiversMutex);
+    auto locker = holdLock(m_workQueueMessageReceiversMutex);
     ASSERT(m_workQueueMessageReceivers.contains(messageReceiverName));
     m_workQueueMessageReceivers.remove(messageReceiverName);
 }
@@ -365,7 +365,7 @@ void Connection::addThreadMessageReceiver(StringReference messageReceiverName, T
 {
     ASSERT(RunLoop::isMain());
 
-    std::lock_guard<Lock> lock(m_threadMessageReceiversLock);
+    auto locker = holdLock(m_threadMessageReceiversLock);
     ASSERT(!m_threadMessageReceivers.contains(messageReceiverName));
 
     m_threadMessageReceivers.add(messageReceiverName, threadMessageReceiver);
@@ -375,7 +375,7 @@ void Connection::removeThreadMessageReceiver(StringReference messageReceiverName
 {
     ASSERT(RunLoop::isMain());
 
-    std::lock_guard<Lock> lock(m_threadMessageReceiversLock);
+    auto locker = holdLock(m_threadMessageReceiversLock);
     ASSERT(m_threadMessageReceivers.contains(messageReceiverName));
 
     m_threadMessageReceivers.remove(messageReceiverName);
@@ -469,7 +469,7 @@ bool Connection::sendMessage(std::unique_ptr<Encoder> encoder, OptionSet<SendOpt
         encoder->setShouldDispatchMessageWhenWaitingForSyncReply(ShouldDispatchWhenWaitingForSyncReply::YesDuringUnboundedIPC);
 
     {
-        std::lock_guard<Lock> lock(m_outgoingMessagesMutex);
+        auto locker = holdLock(m_outgoingMessagesMutex);
         m_outgoingMessages.append(WTFMove(encoder));
     }
     
@@ -501,7 +501,7 @@ std::unique_ptr<Decoder> Connection::waitForMessage(StringReference messageRecei
 
     // First, check if this message is already in the incoming messages queue.
     {
-        std::lock_guard<Lock> lock(m_incomingMessagesMutex);
+        auto locker = holdLock(m_incomingMessagesMutex);
 
         for (auto it = m_incomingMessages.begin(), end = m_incomingMessages.end(); it != end; ++it) {
             std::unique_ptr<Decoder>& message = *it;
@@ -521,7 +521,7 @@ std::unique_ptr<Decoder> Connection::waitForMessage(StringReference messageRecei
     // Don't even start waiting if we have InterruptWaitingIfSyncMessageArrives and there's a sync message already in the queue.
     if (hasIncomingSynchronousMessage && waitForOptions.contains(WaitForOption::InterruptWaitingIfSyncMessageArrives)) {
 #if ASSERT_ENABLED
-        std::lock_guard<Lock> lock(m_waitForMessageMutex);
+        auto locker = holdLock(m_waitForMessageMutex);
         // We don't support having multiple clients waiting for messages.
         ASSERT(!m_waitingForMessage);
 #endif
@@ -531,7 +531,7 @@ std::unique_ptr<Decoder> Connection::waitForMessage(StringReference messageRecei
     WaitForMessageState waitingForMessage(messageReceiverName, messageName, destinationID, waitForOptions);
 
     {
-        std::lock_guard<Lock> lock(m_waitForMessageMutex);
+        auto locker = holdLock(m_waitForMessageMutex);
 
         // We don't support having multiple clients waiting for messages.
         ASSERT(!m_waitingForMessage);
@@ -746,7 +746,7 @@ void Connection::processIncomingMessage(std::unique_ptr<Decoder> message)
 #endif
 
     if (message->isSyncMessage()) {
-        std::lock_guard<Lock> lock(m_incomingSyncMessageCallbackMutex);
+        auto locker = holdLock(m_incomingSyncMessageCallbackMutex);
 
         for (auto& callback : m_incomingSyncMessageCallbacks.values())
             m_incomingSyncMessageCallbackQueue->dispatch(WTFMove(callback));
@@ -756,7 +756,7 @@ void Connection::processIncomingMessage(std::unique_ptr<Decoder> message)
 
     // Check if we're waiting for this message, or if we need to interrupt waiting due to an incoming sync message.
     {
-        std::lock_guard<Lock> lock(m_waitForMessageMutex);
+        auto locker = holdLock(m_waitForMessageMutex);
 
         if (m_waitingForMessage && !m_waitingForMessage->decoder) {
             if (m_waitingForMessage->messageReceiverName == message->messageReceiverName() && m_waitingForMessage->messageName == message->messageName() && m_waitingForMessage->destinationID == message->destinationID()) {
@@ -786,7 +786,7 @@ void Connection::processIncomingMessage(std::unique_ptr<Decoder> message)
 
 uint64_t Connection::installIncomingSyncMessageCallback(WTF::Function<void ()>&& callback)
 {
-    std::lock_guard<Lock> lock(m_incomingSyncMessageCallbackMutex);
+    auto locker = holdLock(m_incomingSyncMessageCallbackMutex);
 
     m_nextIncomingSyncMessageCallbackID++;
 
@@ -800,13 +800,13 @@ uint64_t Connection::installIncomingSyncMessageCallback(WTF::Function<void ()>&&
 
 void Connection::uninstallIncomingSyncMessageCallback(uint64_t callbackID)
 {
-    std::lock_guard<Lock> lock(m_incomingSyncMessageCallbackMutex);
+    auto locker = holdLock(m_incomingSyncMessageCallbackMutex);
     m_incomingSyncMessageCallbacks.remove(callbackID);
 }
 
 bool Connection::hasIncomingSyncMessage()
 {
-    std::lock_guard<Lock> lock(m_incomingMessagesMutex);
+    auto locker = holdLock(m_incomingMessagesMutex);
 
     for (auto& message : m_incomingMessages) {
         if (message->isSyncMessage())
@@ -847,7 +847,7 @@ void Connection::connectionDidClose()
     }
 
     {
-        std::lock_guard<Lock> lock(m_waitForMessageMutex);
+        auto locker = holdLock(m_waitForMessageMutex);
 
         ASSERT(m_shouldWaitForMessages);
         m_shouldWaitForMessages = false;
@@ -890,7 +890,7 @@ void Connection::sendOutgoingMessages()
         std::unique_ptr<Encoder> message;
 
         {
-            std::lock_guard<Lock> lock(m_outgoingMessagesMutex);
+            auto locker = holdLock(m_outgoingMessagesMutex);
             if (m_outgoingMessages.isEmpty())
                 break;
             message = m_outgoingMessages.takeFirst();
@@ -957,7 +957,7 @@ void Connection::didFailToSendSyncMessage()
 void Connection::enqueueIncomingMessage(std::unique_ptr<Decoder> incomingMessage)
 {
     {
-        std::lock_guard<Lock> lock(m_incomingMessagesMutex);
+        auto locker = holdLock(m_incomingMessagesMutex);
 
 #if PLATFORM(COCOA)
         if (m_wasKilled)
@@ -1010,7 +1010,7 @@ void Connection::dispatchMessage(Decoder& decoder)
 
 bool Connection::dispatchMessageToWorkQueueReceiver(std::unique_ptr<Decoder>& message)
 {
-    std::lock_guard<Lock> lock(m_workQueueMessageReceiversMutex);
+    auto locker = holdLock(m_workQueueMessageReceiversMutex);
     auto it = m_workQueueMessageReceivers.find(message->messageReceiverName());
     if (it != m_workQueueMessageReceivers.end()) {
         it->value.first->dispatch([protectedThis = makeRef(*this), workQueueMessageReceiver = it->value.second, decoder = WTFMove(message)]() mutable {
@@ -1025,7 +1025,7 @@ bool Connection::dispatchMessageToThreadReceiver(std::unique_ptr<Decoder>& messa
 {
     RefPtr<ThreadMessageReceiver> protectedThreadMessageReceiver;
     {
-        std::lock_guard<Lock> lock(m_threadMessageReceiversLock);
+        auto locker = holdLock(m_threadMessageReceiversLock);
         protectedThreadMessageReceiver = m_threadMessageReceivers.get(message->messageReceiverName());
     }
 
@@ -1136,7 +1136,7 @@ void Connection::dispatchOneIncomingMessage()
 {
     std::unique_ptr<Decoder> message;
     {
-        std::lock_guard<Lock> lock(m_incomingMessagesMutex);
+        auto locker = holdLock(m_incomingMessagesMutex);
         if (m_incomingMessages.isEmpty())
             return;
 
@@ -1154,7 +1154,7 @@ void Connection::dispatchIncomingMessages()
 
     size_t messagesToProcess = 0;
     {
-        std::lock_guard<Lock> lock(m_incomingMessagesMutex);
+        auto locker = holdLock(m_incomingMessagesMutex);
         if (m_incomingMessages.isEmpty())
             return;
 
@@ -1182,7 +1182,7 @@ void Connection::dispatchIncomingMessages()
 
     for (size_t i = 1; i < messagesToProcess; ++i) {
         {
-            std::lock_guard<Lock> lock(m_incomingMessagesMutex);
+            auto locker = holdLock(m_incomingMessagesMutex);
             if (m_incomingMessages.isEmpty())
                 return;
 
index 728c847..52f78fc 100644 (file)
@@ -57,7 +57,7 @@ public:
 
     void didReceiveResponse(uint64_t requestID, std::unique_ptr<T> response)
     {
-        std::lock_guard<Lock> lock(m_mutex);
+        auto locker = holdLock(m_mutex);
         ASSERT(!m_responses.contains(requestID));
 
         m_responses.set(requestID, WTFMove(response));
index e3436f3..01e4321 100644 (file)
@@ -250,7 +250,7 @@ static void pageDidDrawToImage(const WebKit::ShareableBitmap::Handle& imageHandl
         return;
     }
 
-    std::lock_guard<Lock> lock(_printingCallbackMutex);
+    auto locker = holdLock(_printingCallbackMutex);
 
     ASSERT([self _hasPageRects]);
     ASSERT(_printedPagesData.isEmpty());
@@ -366,7 +366,7 @@ static void prepareDataForPrintingOnSecondaryThread(WKPrintingView *view)
 {
     ASSERT(RunLoop::isMain());
 
-    std::lock_guard<Lock> lock(view->_printingCallbackMutex);
+    auto locker = holdLock(view->_printingCallbackMutex);
 
     // We may have received page rects while a message to call this function traveled from secondary thread to main one.
     if ([view _hasPageRects]) {
index 1959edd..cb951c6 100644 (file)
@@ -1,3 +1,15 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        * DOM/DOMInternal.mm:
+        (getDOMWrapper):
+        (addDOMWrapper):
+        (removeDOMWrapper):
+
 2020-02-28  Jer Noble  <jer.noble@apple.com>
 
         [GPUP] Implement Modern EME API in the GPU Process
index 01f5e91..3a706c4 100644 (file)
@@ -56,7 +56,7 @@ static HashMap<DOMObjectInternal*, NSObject *>& wrapperCache()
 NSObject* getDOMWrapper(DOMObjectInternal* impl)
 {
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-    std::lock_guard<Lock> lock(wrapperCacheLock);
+    auto locker = holdLock(wrapperCacheLock);
 #endif
     return wrapperCache().get(impl);
 }
@@ -64,7 +64,7 @@ NSObject* getDOMWrapper(DOMObjectInternal* impl)
 void addDOMWrapper(NSObject* wrapper, DOMObjectInternal* impl)
 {
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-    std::lock_guard<Lock> lock(wrapperCacheLock);
+    auto locker = holdLock(wrapperCacheLock);
 #endif
     wrapperCache().set(impl, wrapper);
 }
@@ -72,7 +72,7 @@ void addDOMWrapper(NSObject* wrapper, DOMObjectInternal* impl)
 void removeDOMWrapper(DOMObjectInternal* impl)
 {
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-    std::lock_guard<Lock> lock(wrapperCacheLock);
+    auto locker = holdLock(wrapperCacheLock);
 #endif
     wrapperCache().remove(impl);
 }
index 930a246..04eca8a 100644 (file)
@@ -1,3 +1,12 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        * bmalloc/Mutex.h:
+
 2020-02-28  Saam Barati  <sbarati@apple.com>
 
         Clean up code with how we choose Gigacage sizes and whether or not to use Wasm fast memory
index 240c85e..f4cc2aa 100644 (file)
@@ -38,7 +38,7 @@ namespace bmalloc {
 class Mutex;
 
 using UniqueLockHolder = std::unique_lock<Mutex>;
-using LockHolder = std::lock_guard<Mutex>;
+using LockHolder = std::scoped_lock<Mutex>;
 
 class Mutex {
 public:
index 36b931a..605ade6 100644 (file)
@@ -1,3 +1,29 @@
+2020-02-29  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Remove std::lock_guard
+        https://bugs.webkit.org/show_bug.cgi?id=206451
+
+        Reviewed by Anders Carlsson.
+
+        Add std::lock_guard lint rule to prevent from using it.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_lock_guard):
+        (check_style):
+        (CppChecker):
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_lock_guard):
+        * TestWebKitAPI/Tests/WTF/Condition.cpp:
+        * TestWebKitAPI/Tests/WTF/ParkingLot.cpp:
+        * TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp:
+        (assertHasObjects):
+        (assertHasOnlyObjects):
+        * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
+        (WTR::AXThread::dispatch):
+        (WTR::AXThread::dispatchFunctionsFromAXThread):
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
+        (WTR::AXThread::initializeRunLoop):
+
 2020-02-29  Per Arne Vollan  <pvollan@apple.com>
 
         [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
index ecec65c..9693ed3 100644 (file)
@@ -2505,6 +2505,26 @@ def check_wtf_make_unique(clean_lines, line_number, file_state, error):
               "Use 'WTF::makeUnique<{typename}>' instead of 'std::make_unique<{typename}>'.".format(typename=typename))
 
 
+def check_lock_guard(clean_lines, line_number, file_state, error):
+    """Looks for use of 'std::lock_guard<>' which should be replaced with 'WTF::Locker'.
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
+      error: The function to call with any errors found.
+    """
+
+    line = clean_lines.elided[line_number]  # Get rid of comments and strings.
+
+    using_std_lock_guard_search = search(r'\bstd::lock_guard\s*<([^(]+)', line)
+    if not using_std_lock_guard_search:
+        return
+
+    error(line_number, 'runtime/lock_guard', 4, "Use 'auto locker = holdLock(mutex)' instead of 'std::lock_guard<>'.")
+
+
 def check_ctype_functions(clean_lines, line_number, file_state, error):
     """Looks for use of the standard functions in ctype.h and suggest they be replaced
        by use of equivilent ones in <wtf/ASCIICType.h>?.
@@ -3065,6 +3085,7 @@ def check_style(clean_lines, line_number, file_extension, class_state, file_stat
     check_wtf_move(clean_lines, line_number, file_state, error)
     check_wtf_optional(clean_lines, line_number, file_state, error)
     check_wtf_make_unique(clean_lines, line_number, file_state, error)
+    check_lock_guard(clean_lines, line_number, file_state, error)
     check_ctype_functions(clean_lines, line_number, file_state, error)
     check_switch_indentation(clean_lines, line_number, error)
     check_braces(clean_lines, line_number, file_state, error)
@@ -4226,6 +4247,7 @@ class CppChecker(object):
         'runtime/int',
         'runtime/invalid_increment',
         'runtime/leaky_pattern',
+        'runtime/lock_guard',
         'runtime/max_min_macros',
         'runtime/memset',
         'runtime/printf',
index e0bc4a4..eea293d 100644 (file)
@@ -5373,6 +5373,24 @@ class WebKitStyleTest(CppStyleTestBase):
             "  [runtime/wtf_optional] [4]",
             'foo.cpp')
 
+    def test_lock_guard(self):
+        self.assert_lint(
+            'auto locker = holdLock(mutex);',
+            '',
+            'foo.cpp')
+
+        self.assert_lint(
+            'std::lock_guard<Lock> locker(mutex);',
+            "Use 'auto locker = holdLock(mutex)' instead of 'std::lock_guard<>'."
+            "  [runtime/lock_guard] [4]",
+            'foo.cpp')
+
+        self.assert_lint(
+            'std::lock_guard<Lock> locker(mutex);',
+            "Use 'auto locker = holdLock(mutex)' instead of 'std::lock_guard<>'."
+            "  [runtime/lock_guard] [4]",
+            'foo.mm')
+
     def test_ctype_fucntion(self):
         self.assert_lint(
             'int i = isascii(8);',
index 26c8f99..0ec105d 100644 (file)
@@ -118,7 +118,7 @@ void runTest(
                     notify(notifyStyle, fullCondition, shouldNotify);
 
                     {
-                        std::lock_guard<Lock> locker(receivedLock);
+                        auto locker = holdLock(receivedLock);
                         received.append(result);
                     }
                 }
@@ -155,7 +155,7 @@ void runTest(
         thread->waitForCompletion();
 
     {
-        std::lock_guard<Lock> locker(lock);
+        auto locker = holdLock(lock);
         shouldContinue = false;
     }
     emptyCondition.notifyAll();
index e00a09b..fb82790 100644 (file)
@@ -51,7 +51,7 @@ struct SingleLatchTest {
                     [&] () {
                         down();
 
-                        std::lock_guard<std::mutex> locker(lock);
+                        std::scoped_lock<std::mutex> locker(lock);
                         awake.add(Thread::current());
                         lastAwoken = &Thread::current();
                         condition.notify_one();
index 08b72aa..cbee771 100644 (file)
@@ -78,7 +78,7 @@ static void assertHasObjects(IsoHeap<heapType>& heap, std::set<void*> pointers)
         return;
     }
     auto& impl = heap.impl();
-    std::lock_guard<bmalloc::Mutex> locker(impl.lock);
+    std::scoped_lock<bmalloc::Mutex> locker(impl.lock);
     impl.forEachLiveObject(
         locker,
         [&] (void* object) {
@@ -95,7 +95,7 @@ static void assertHasOnlyObjects(IsoHeap<heapType>& heap, std::set<void*> pointe
         return;
     }
     auto& impl = heap.impl();
-    std::lock_guard<bmalloc::Mutex> locker(impl.lock);
+    std::scoped_lock<bmalloc::Mutex> locker(impl.lock);
     impl.forEachLiveObject(
         locker,
         [&] (void* object) {
index c9669c1..1242238 100644 (file)
@@ -137,7 +137,7 @@ void AXThread::dispatch(Function<void()>&& function)
     axThread.createThreadIfNeeded();
 
     {
-        std::lock_guard<Lock> lock(axThread.m_functionsMutex);
+        auto locker = holdLock(axThread.m_functionsMutex);
         axThread.m_functions.append(WTFMove(function));
     }
 
@@ -185,7 +185,7 @@ void AXThread::dispatchFunctionsFromAXThread()
     Vector<Function<void()>> functions;
 
     {
-        std::lock_guard<Lock> lock(m_functionsMutex);
+        auto locker = holdLock(m_functionsMutex);
         functions = WTFMove(m_functions);
     }
 
index a94de38..e83ad67 100644 (file)
@@ -129,7 +129,7 @@ void AXThread::initializeRunLoop()
 {
     // Initialize the run loop.
     {
-        std::lock_guard<Lock> lock(m_initializeRunLoopMutex);
+        auto locker = holdLock(m_initializeRunLoopMutex);
 
         m_threadRunLoop = CFRunLoopGetCurrent();