Title: [277932] trunk
Revision
277932
Author
cdu...@apple.com
Date
2021-05-23 12:55:32 -0700 (Sun, 23 May 2021)

Log Message

Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis
https://bugs.webkit.org/show_bug.cgi?id=226145

Reviewed by Darin Adler.

Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis.
Instead, use the following pattern which is supported:
```
if (lock.tryLock()) {
    Locker locker { AdoptLock, lock };
    // ...
}
```

Source/_javascript_Core:

* heap/Heap.cpp:
(JSC::Heap::resumeThePeriphery):
* runtime/VMTraps.cpp:
(JSC::VMTraps::tryInstallTrapBreakpoints):

Source/WebCore:

* Modules/webaudio/AudioBufferSourceNode.cpp:
(WebCore::AudioBufferSourceNode::process):
* Modules/webaudio/AudioWorkletNode.cpp:
(WebCore::AudioWorkletNode::process):
* Modules/webaudio/ConvolverNode.cpp:
(WebCore::ConvolverNode::process):
* Modules/webaudio/MediaElementAudioSourceNode.cpp:
(WebCore::MediaElementAudioSourceNode::process):
* Modules/webaudio/MediaStreamAudioSourceNode.cpp:
(WebCore::MediaStreamAudioSourceNode::process):
* Modules/webaudio/OscillatorNode.cpp:
(WebCore::OscillatorNode::process):
* Modules/webaudio/PannerNode.cpp:
(WebCore::PannerNode::process):
* Modules/webaudio/ScriptProcessorNode.cpp:
(WebCore::ScriptProcessorNode::process):
* Modules/webaudio/WaveShaperProcessor.cpp:
(WebCore::WaveShaperProcessor::process):
* platform/audio/ReverbConvolver.cpp:
(WebCore::ReverbConvolver::process):
* platform/graphics/ShadowBlur.cpp:
(WebCore::ScratchBuffer::purgeTimerFired):
(WebCore::ShadowBlur::drawRectShadowWithTiling):
(WebCore::ShadowBlur::drawInsetShadowWithTiling):
* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
(WebCore::AudioSourceProviderAVFObjC::provideInput):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample):
* platform/mediastream/mac/WebAudioSourceProviderCocoa.mm:
(WebCore::WebAudioSourceProviderCocoa::provideInput):
* workers/WorkerOrWorkletThread.cpp:
(WebCore::WorkerOrWorkletThread::stop):

Source/WTF:

* wtf/CheckedLock.h:
* wtf/Lock.h:
* wtf/Locker.h:
(WTF::Locker::Locker):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (277931 => 277932)


--- trunk/Source/_javascript_Core/ChangeLog	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-05-23 19:55:32 UTC (rev 277932)
@@ -1,3 +1,24 @@
+2021-05-23  Chris Dumez  <cdu...@apple.com>
+
+        Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis
+        https://bugs.webkit.org/show_bug.cgi?id=226145
+
+        Reviewed by Darin Adler.
+
+        Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis.
+        Instead, use the following pattern which is supported:
+        ```
+        if (lock.tryLock()) {
+            Locker locker { AdoptLock, lock };
+            // ...
+        }
+        ```
+
+        * heap/Heap.cpp:
+        (JSC::Heap::resumeThePeriphery):
+        * runtime/VMTraps.cpp:
+        (JSC::VMTraps::tryInstallTrapBreakpoints):
+
 2021-05-22  Mark Lam  <mark....@apple.com>
 
         Use singleton thunks for virtual calls.

Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (277931 => 277932)


--- trunk/Source/_javascript_Core/heap/Heap.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -1707,7 +1707,8 @@
             bool remove = false;
             if (visitor.hasAcknowledgedThatTheMutatorIsResumed())
                 remove = true;
-            else if (auto locker = tryHoldLock(visitor.rightToRun())) {
+            else if (visitor.rightToRun().tryLock()) {
+                Locker locker { AdoptLock, visitor.rightToRun() };
                 visitor.updateMutatorIsStopped(locker);
                 remove = true;
             }

Modified: trunk/Source/_javascript_Core/runtime/VMTraps.cpp (277931 => 277932)


--- trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -137,10 +137,10 @@
     }
 
     if (JITCode::isOptimizingJIT(foundCodeBlock->jitType())) {
-        auto locker = tryHoldLock(*m_lock);
-        if (!locker)
+        if (!m_lock->tryLock())
             return; // Let the SignalSender try again later.
 
+        Locker locker { AdoptLock, *m_lock };
         if (!needHandling(VMTraps::AsyncEvents)) {
             // Too late. Someone else already handled the trap.
             return;

Modified: trunk/Source/WTF/ChangeLog (277931 => 277932)


--- trunk/Source/WTF/ChangeLog	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WTF/ChangeLog	2021-05-23 19:55:32 UTC (rev 277932)
@@ -1,3 +1,24 @@
+2021-05-23  Chris Dumez  <cdu...@apple.com>
+
+        Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis
+        https://bugs.webkit.org/show_bug.cgi?id=226145
+
+        Reviewed by Darin Adler.
+
+        Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis.
+        Instead, use the following pattern which is supported:
+        ```
+        if (lock.tryLock()) {
+            Locker locker { AdoptLock, lock };
+            // ...
+        }
+        ```
+
+        * wtf/CheckedLock.h:
+        * wtf/Lock.h:
+        * wtf/Locker.h:
+        (WTF::Locker::Locker):
+
 2021-05-23  Mark Lam  <mark....@apple.com>
 
         Build fix for JSCOnly-Linux-AArch64 bot.

Modified: trunk/Source/WTF/wtf/CheckedLock.h (277931 => 277932)


--- trunk/Source/WTF/wtf/CheckedLock.h	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WTF/wtf/CheckedLock.h	2021-05-23 19:55:32 UTC (rev 277932)
@@ -25,7 +25,6 @@
 
 #pragma once
 
-#include <mutex>
 #include <wtf/Lock.h>
 #include <wtf/Locker.h>
 #include <wtf/ThreadSafetyAnalysis.h>
@@ -40,12 +39,12 @@
 //   class MyValue : public ThreadSafeRefCounted<MyValue>
 //   {
 //   public:
-//       void setValue(int value) { Lochker holdLock { m_lock }; m_value = value;  }
+//       void setValue(int value) { Locker holdLock { m_lock }; m_value = value;  }
 //       void maybeSetOtherValue(int value)
 //       {
 //           if (!m_lock.tryLock())
 //              return;
-//           Locker locker { AdoptLockTag { }, m_otherLock };
+//           Locker locker { AdoptLock, m_otherLock };
 //           m_otherValue = value;
 //       }
 //   private:
@@ -75,8 +74,6 @@
 // declaration.
 inline void assertIsHeld(const CheckedLock& lock) WTF_ASSERTS_ACQUIRED_LOCK(lock) { ASSERT_UNUSED(lock, lock.isHeld()); }
 
-using AdoptLockTag = std::adopt_lock_t;
-
 // Locker specialization to use with CheckedLock.
 // Non-movable simple scoped lock holder.
 // Example: Locker locker { m_lock };
@@ -109,4 +106,3 @@
 
 using WTF::assertIsHeld;
 using WTF::CheckedLock;
-using WTF::AdoptLockTag;

Modified: trunk/Source/WTF/wtf/Locker.h (277931 => 277932)


--- trunk/Source/WTF/wtf/Locker.h	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WTF/wtf/Locker.h	2021-05-23 19:55:32 UTC (rev 277932)
@@ -28,6 +28,7 @@
 
 #pragma once
 
+#include <mutex>
 #include <wtf/Assertions.h>
 #include <wtf/Atomics.h>
 #include <wtf/Compiler.h>
@@ -54,11 +55,15 @@
 
 template<typename T> class DropLockForScope;
 
+using AdoptLockTag = std::adopt_lock_t;
+constexpr AdoptLockTag AdoptLock;
+
 template<typename T>
 class Locker : public AbstractLocker {
 public:
     explicit Locker(T& lockable) : m_lockable(&lockable) { lock(); }
     explicit Locker(T* lockable) : m_lockable(lockable) { lock(); }
+    explicit Locker(AdoptLockTag, T& lockable) : m_lockable(&lockable) { }
 
     // You should be wary of using this constructor. It's only applicable
     // in places where there is a locking protocol for a particular object
@@ -137,14 +142,6 @@
 };
 
 template<typename LockType>
-Locker<LockType> tryHoldLock(LockType&) WARN_UNUSED_RETURN;
-template<typename LockType>
-Locker<LockType> tryHoldLock(LockType& lock)
-{
-    return Locker<LockType>::tryLock(lock);
-}
-
-template<typename LockType>
 class DropLockForScope : private AbstractLocker {
     WTF_FORBID_HEAP_ALLOCATION(DropLockForScope);
 public:
@@ -166,6 +163,7 @@
 }
 
 using WTF::AbstractLocker;
+using WTF::AdoptLock;
 using WTF::Locker;
 using WTF::NoLockingNecessaryTag;
 using WTF::NoLockingNecessary;

Modified: trunk/Source/WTF/wtf/Logger.h (277931 => 277932)


--- trunk/Source/WTF/wtf/Logger.h	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WTF/wtf/Logger.h	2021-05-23 19:55:32 UTC (rev 277932)
@@ -325,7 +325,7 @@
         if (!observerLock().tryLock())
             return;
 
-        Locker locker { AdoptLockTag { }, observerLock() };
+        Locker locker { AdoptLock, observerLock() };
         for (Observer& observer : observers())
             observer.didLogMessage(channel, level, { ConsoleLogValue<Argument>::toValue(arguments)... });
     }
@@ -356,7 +356,7 @@
         if (!observerLock().tryLock())
             return;
 
-        Locker locker { AdoptLockTag { }, observerLock() };
+        Locker locker { AdoptLock, observerLock() };
         for (Observer& observer : observers())
             observer.didLogMessage(channel, level, { ConsoleLogValue<Argument>::toValue(arguments)... });
     }

Modified: trunk/Source/WebCore/ChangeLog (277931 => 277932)


--- trunk/Source/WebCore/ChangeLog	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/ChangeLog	2021-05-23 19:55:32 UTC (rev 277932)
@@ -1,3 +1,52 @@
+2021-05-23  Chris Dumez  <cdu...@apple.com>
+
+        Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis
+        https://bugs.webkit.org/show_bug.cgi?id=226145
+
+        Reviewed by Darin Adler.
+
+        Drop WTF::tryHoldLock() as it is incompatible with Clang Thread Safety Analysis.
+        Instead, use the following pattern which is supported:
+        ```
+        if (lock.tryLock()) {
+            Locker locker { AdoptLock, lock };
+            // ...
+        }
+        ```
+
+        * Modules/webaudio/AudioBufferSourceNode.cpp:
+        (WebCore::AudioBufferSourceNode::process):
+        * Modules/webaudio/AudioWorkletNode.cpp:
+        (WebCore::AudioWorkletNode::process):
+        * Modules/webaudio/ConvolverNode.cpp:
+        (WebCore::ConvolverNode::process):
+        * Modules/webaudio/MediaElementAudioSourceNode.cpp:
+        (WebCore::MediaElementAudioSourceNode::process):
+        * Modules/webaudio/MediaStreamAudioSourceNode.cpp:
+        (WebCore::MediaStreamAudioSourceNode::process):
+        * Modules/webaudio/OscillatorNode.cpp:
+        (WebCore::OscillatorNode::process):
+        * Modules/webaudio/PannerNode.cpp:
+        (WebCore::PannerNode::process):
+        * Modules/webaudio/ScriptProcessorNode.cpp:
+        (WebCore::ScriptProcessorNode::process):
+        * Modules/webaudio/WaveShaperProcessor.cpp:
+        (WebCore::WaveShaperProcessor::process):
+        * platform/audio/ReverbConvolver.cpp:
+        (WebCore::ReverbConvolver::process):
+        * platform/graphics/ShadowBlur.cpp:
+        (WebCore::ScratchBuffer::purgeTimerFired):
+        (WebCore::ShadowBlur::drawRectShadowWithTiling):
+        (WebCore::ShadowBlur::drawInsetShadowWithTiling):
+        * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
+        (WebCore::AudioSourceProviderAVFObjC::provideInput):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample):
+        * platform/mediastream/mac/WebAudioSourceProviderCocoa.mm:
+        (WebCore::WebAudioSourceProviderCocoa::provideInput):
+        * workers/WorkerOrWorkletThread.cpp:
+        (WebCore::WorkerOrWorkletThread::stop):
+
 2021-05-22  Chris Dumez  <cdu...@apple.com>
 
         Adopt CheckedLock in more places

Modified: trunk/Source/WebCore/Modules/speech/SpeechRecognitionCaptureSourceImpl.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/speech/SpeechRecognitionCaptureSourceImpl.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/speech/SpeechRecognitionCaptureSourceImpl.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -88,7 +88,7 @@
     if (!m_dataSourceLock.tryLock())
         return false;
 
-    Locker locker { AdoptLockTag { }, m_dataSourceLock };
+    Locker locker { AdoptLock, m_dataSourceLock };
 
     auto dataSource = AudioSampleDataSource::create(audioDescription.sampleRate() * 1, m_source.get());
     if (dataSource->setInputFormat(audioDescription)) {

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -102,13 +102,13 @@
         return;
     }
 
-    // The audio thread can't block on this lock, so we use tryHoldLock() instead.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
-        // Too bad - tryHoldLock() failed. We must be in the middle of changing buffers and were already outputting silence anyway.
+    // The audio thread can't block on this lock, so we use tryLock() instead.
+    if (!m_processLock.tryLock()) {
+        // Too bad - tryLock() failed. We must be in the middle of changing buffers and were already outputting silence anyway.
         outputBus.zero();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
 
     if (!buffer()) {
         outputBus.zero();

Modified: trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -329,7 +329,7 @@
     {
         if (!m_eventsLock.tryLock())
             return WTF::nullopt;
-        Locker locker { AdoptLockTag { }, m_eventsLock };
+        Locker locker { AdoptLock, m_eventsLock };
         if (!m_events.size() || Seconds { context.currentTime() } < m_events[0].time())
             return WTF::nullopt;
     }
@@ -351,7 +351,7 @@
         std::fill_n(values, numberOfValues, defaultValue);
         return defaultValue;
     }
-    Locker locker { AdoptLockTag { }, m_eventsLock };
+    Locker locker { AdoptLock, m_eventsLock };
 
     float value = valuesForFrameRangeImpl(startFrame, endFrame, defaultValue, values, numberOfValues, sampleRate, controlRate);
 
@@ -988,7 +988,7 @@
 {
     if (!m_eventsLock.tryLock())
         return true;
-    Locker locker { AdoptLockTag { }, m_eventsLock };
+    Locker locker { AdoptLock, m_eventsLock };
 
     // Return false if there are no events in the time range.
     auto endFrame = startFrame + AudioUtilities::renderQuantumSize;

Modified: trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -191,13 +191,21 @@
 {
     ASSERT(!isMainThread());
 
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker || !m_processor || &Thread::current() != m_workletThread) {
-        // We're not ready yet or we are getting destroyed. In this case, we output silence.
+    auto zeroOutput = [&] {
         for (unsigned i = 0; i < numberOfOutputs(); ++i)
             output(i)->bus()->zero();
+    };
+
+    if (!m_processLock.tryLock()) {
+        zeroOutput();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
+    if (!m_processor || &Thread::current() != m_workletThread) {
+        // We're not ready yet or we are getting destroyed. In this case, we output silence.
+        zeroOutput();
+        return;
+    }
 
     // If the input is not connected, pass nullptr to the processor.
     for (unsigned i = 0; i < numberOfInputs(); ++i)

Modified: trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -92,12 +92,12 @@
     ASSERT(outputBus);
 
     // Synchronize with possible dynamic changes to the impulse response.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
-        // Too bad - tryHoldLock() failed. We must be in the middle of setting a new impulse response.
+    if (!m_processLock.tryLock()) {
+        // Too bad - tryLock() failed. We must be in the middle of setting a new impulse response.
         outputBus->zero();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
 
     if (!isInitialized() || !m_reverb.get())
         outputBus->zero();

Modified: trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -155,15 +155,16 @@
         return;
     }
 
-    // Use tryHoldLock() to avoid contention in the real-time audio thread.
+    // Use tryLock() to avoid contention in the real-time audio thread.
     // If we fail to acquire the lock then the HTMLMediaElement must be in the middle of
     // reconfiguring its playback engine, so we output silence in this case.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
+    if (!m_processLock.tryLock()) {
         // We failed to acquire the lock.
         outputBus->zero();
         return;
     }
+
+    Locker locker { AdoptLock, m_processLock };
     if (m_sourceNumberOfChannels != outputBus->numberOfChannels()) {
         outputBus->zero();
         return;

Modified: trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -139,15 +139,15 @@
         return;
     }
 
-    // Use tryHoldLock() to avoid contention in the real-time audio thread.
+    // Use tryLock() to avoid contention in the real-time audio thread.
     // If we fail to acquire the lock then the MediaStream must be in the middle of
     // a format change, so we output silence in this case.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
+    if (!m_processLock.tryLock()) {
         // We failed to acquire the lock.
         outputBus->zero();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
     if (m_sourceNumberOfChannels != outputBus->numberOfChannels()) {
         outputBus->zero();
         return;

Modified: trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -349,13 +349,13 @@
     if (framesToProcess > m_phaseIncrements.size())
         return;
 
-    // The audio thread can't block on this lock, so we use tryHoldLock() instead.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
-        // Too bad - tryHoldLock() failed. We must be in the middle of changing wave-tables.
+    // The audio thread can't block on this lock, so we use tryLock() instead.
+    if (!m_processLock.tryLock()) {
+        // Too bad - tryLock() failed. We must be in the middle of changing wave-tables.
         outputBus.zero();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
 
     // We must access m_periodicWave only inside the lock.
     if (!m_periodicWave.get()) {

Modified: trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -129,13 +129,13 @@
         }
     }
 
-    // The audio thread can't block on this lock, so we use tryHoldLock() instead.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
-        // Too bad - tryHoldLock() failed. We must be in the middle of changing the panner.
+    // The audio thread can't block on this lock, so we use tryLock() instead.
+    if (!m_processLock.tryLock()) {
+        // Too bad - tryLock() failed. We must be in the middle of changing the panner.
         destination->zero();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
 
     if ((hasSampleAccurateValues() || listener().hasSampleAccurateValues()) && (shouldUseARate() || listener().shouldUseARate())) {
         processSampleAccurateValues(destination, source, framesToProcess);

Modified: trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -158,13 +158,13 @@
     unsigned bufferIndex = this->bufferIndex();
     ASSERT(bufferIndex < bufferCount);
 
-    auto locker = tryHoldLock(m_bufferLocks[bufferIndex]);
-    if (!locker) {
+    if (!m_bufferLocks[bufferIndex].tryLock()) {
         // We're late in handling the previous request. The main thread must be
         // very busy. The best we can do is clear out the buffer ourself here.
         outputBus->zero();
         return;
     }
+    Locker locker { AdoptLock, m_bufferLocks[bufferIndex] };
     
     AudioBuffer* inputBuffer = m_inputBuffers[bufferIndex].get();
     AudioBuffer* outputBuffer = m_outputBuffers[bufferIndex].get();

Modified: trunk/Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp (277931 => 277932)


--- trunk/Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -83,13 +83,13 @@
     if (!channelCountMatches)
         return;
 
-    // The audio thread can't block on this lock, so we use tryHoldLock() instead.
-    auto locker = tryHoldLock(m_processLock);
-    if (!locker) {
-        // Too bad - tryHoldLock() failed. We must be in the middle of a setCurve() call.
+    // The audio thread can't block on this lock, so we use tryLock() instead.
+    if (!m_processLock.tryLock()) {
+        // Too bad - tryLock() failed. We must be in the middle of a setCurve() call.
         destination->zero();
         return;
     }
+    Locker locker { AdoptLock, m_processLock };
 
     // For each channel of our input, process using the corresponding WaveShaperDSPKernel into the output channel.
     for (unsigned i = 0; i < m_kernels.size(); ++i)

Modified: trunk/Source/WebCore/platform/audio/AudioDestination.h (277931 => 277932)


--- trunk/Source/WebCore/platform/audio/AudioDestination.h	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/audio/AudioDestination.h	2021-05-23 19:55:32 UTC (rev 277932)
@@ -97,7 +97,7 @@
 inline void AudioDestination::callRenderCallback(AudioBus* sourceBus, AudioBus* destinationBus, size_t framesToProcess, const AudioIOPosition& outputPosition)
 {
     if (m_callbackLock.tryLock()) {
-        Locker locker { AdoptLockTag { }, m_callbackLock };
+        Locker locker { AdoptLock, m_callbackLock };
         if (m_callback) {
             m_callback->render(sourceBus, destinationBus, framesToProcess, outputPosition);
             return;

Modified: trunk/Source/WebCore/platform/audio/ReverbConvolver.cpp (277931 => 277932)


--- trunk/Source/WebCore/platform/audio/ReverbConvolver.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/audio/ReverbConvolver.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -202,9 +202,9 @@
     // signal from time to time, since we'll get to it the next time we're called.  We're called repeatedly
     // and frequently (around every 3ms).  The background thread is processing well into the future and has a considerable amount of 
     // leeway here...
-    auto locker = tryHoldLock(m_backgroundThreadLock);
-    if (!locker)
+    if (!m_backgroundThreadLock.tryLock())
         return;
+    Locker locker { AdoptLock, m_backgroundThreadLock };
 
     m_moreInputBuffered = true;
     m_backgroundThreadConditionVariable.notifyOne();

Modified: trunk/Source/WebCore/platform/audio/cocoa/AudioDestinationCocoa.cpp (277931 => 277932)


--- trunk/Source/WebCore/platform/audio/cocoa/AudioDestinationCocoa.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/audio/cocoa/AudioDestinationCocoa.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -222,7 +222,7 @@
     if (!m_dispatchToRenderThreadLock.tryLock())
         return -1;
 
-    Locker locker { AdoptLockTag { }, m_dispatchToRenderThreadLock };
+    Locker locker { AdoptLock, m_dispatchToRenderThreadLock };
     if (!m_dispatchToRenderThread)
         renderOnRenderingTheadIfPlaying(framesToRender);
     else {

Modified: trunk/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp (277931 => 277932)


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -162,7 +162,7 @@
     if (!m_adapterLock.tryLock())
         return;
 
-    Locker locker { AdoptLockTag { }, m_adapterLock };
+    Locker locker { AdoptLock, m_adapterLock };
     for (auto& it : m_adapters)
         copyGStreamerBuffersToAudioChannel(it.value.get(), bus, it.key - 1, framesToProcess);
 }

Modified: trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp (277931 => 277932)


--- trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -411,7 +411,7 @@
     if (!priv->dispatchToRenderThreadLock.tryLock())
         return;
 
-    Locker locker { AdoptLockTag { }, priv->dispatchToRenderThreadLock };
+    Locker locker { AdoptLock, priv->dispatchToRenderThreadLock };
 
     if (!priv->dispatchToRenderThreadFunction)
         webKitWebAudioSrcRenderAndPushFrames(GRefPtr<GstElement>(GST_ELEMENT_CAST(src)), WTFMove(*channelBufferList));

Modified: trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp (277931 => 277932)


--- trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -135,8 +135,10 @@
     void purgeTimerFired()
     {
         ASSERT(isMainThread());
-        if (auto locker = tryHoldLock(lock()))
+        if (lock().tryLock()) {
             clearScratchBuffer();
+            lock().unlock();
+        }
     }
 
     void clearScratchBuffer()
@@ -694,7 +696,7 @@
 {
     RefPtr<ImageBuffer> layerImageBuffer;
 #if USE(CG)
-    auto locker = tryHoldLock(ScratchBuffer::lock());
+    auto locker = Locker<Lock>::tryLock(ScratchBuffer::lock());
     if (locker) {
         layerImageBuffer = ScratchBuffer::singleton().getScratchBuffer(templateSize);
         if (!layerImageBuffer)
@@ -754,7 +756,7 @@
 {
     RefPtr<ImageBuffer> layerImageBuffer;
 #if USE(CG)
-    auto locker = tryHoldLock(ScratchBuffer::lock());
+    auto locker = Locker<Lock>::tryLock(ScratchBuffer::lock());
     if (locker) {
         layerImageBuffer = ScratchBuffer::singleton().getScratchBuffer(templateSize);
         if (!layerImageBuffer)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm (277931 => 277932)


--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm	2021-05-23 19:55:32 UTC (rev 277932)
@@ -94,7 +94,7 @@
 
 void AudioSourceProviderAVFObjC::provideInput(AudioBus* bus, size_t framesToProcess)
 {
-    // Protect access to m_ringBuffer by using tryHoldLock(). If we failed
+    // Protect access to m_ringBuffer by using tryLock(). If we failed
     // to aquire, a re-configure is underway, and m_ringBuffer is unsafe to access.
     // Emit silence.
     if (!m_tapStorage) {
@@ -102,12 +102,17 @@
         return;
     }
 
-    auto locker = tryHoldLock(m_tapStorage->lock);
-    if (!locker || !m_ringBuffer) {
+    if (!m_tapStorage->lock.tryLock()) {
         bus->zero();
         return;
     }
+    Locker locker { AdoptLock, m_tapStorage->lock };
 
+    if (!m_ringBuffer) {
+        bus->zero();
+        return;
+    }
+
     uint64_t startFrame = 0;
     uint64_t endFrame = 0;
     uint64_t seekTo = std::exchange(m_seekTo, NoSeek);

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (277931 => 277932)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm	2021-05-23 19:55:32 UTC (rev 277932)
@@ -254,9 +254,9 @@
     if (!m_visible)
         return;
 
-    auto locker = tryHoldLock(m_sampleBufferDisplayLayerLock);
-    if (!locker)
+    if (!m_sampleBufferDisplayLayerLock.tryLock())
         return;
+    Locker locker { AdoptLock, m_sampleBufferDisplayLayerLock };
 
     if (!m_canEnqueueDisplayLayer || !m_sampleBufferDisplayLayer || m_sampleBufferDisplayLayer->didFail())
         return;

Modified: trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererUnit.cpp (277931 => 277932)


--- trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererUnit.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererUnit.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -144,7 +144,7 @@
     if (!m_pendingRenderSourcesLock.tryLock())
         return;
 
-    Locker locker { AdoptLockTag { }, m_pendingRenderSourcesLock };
+    Locker locker { AdoptLock, m_pendingRenderSourcesLock };
     if (!m_hasPendingRenderSources)
         return;
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderCocoa.mm (277931 => 277932)


--- trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderCocoa.mm	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderCocoa.mm	2021-05-23 19:55:32 UTC (rev 277932)
@@ -65,11 +65,15 @@
 
 void WebAudioSourceProviderCocoa::provideInput(AudioBus* bus, size_t framesToProcess)
 {
-    auto locker = tryHoldLock(m_lock);
-    if (!locker || !m_dataSource || !m_audioBufferList) {
+    if (!m_lock.tryLock()) {
         bus->zero();
         return;
     }
+    Locker locker { AdoptLock, m_lock };
+    if (!m_dataSource || !m_audioBufferList) {
+        bus->zero();
+        return;
+    }
 
     if (m_writeCount <= m_readCount) {
         bus->zero();

Modified: trunk/Source/WebCore/workers/WorkerOrWorkletThread.cpp (277931 => 277932)


--- trunk/Source/WebCore/workers/WorkerOrWorkletThread.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletThread.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -207,8 +207,7 @@
     // Mutex protection is necessary to ensure that m_workerGlobalScope isn't changed by
     // WorkerThread::workerThread() while we're accessing it. Note also that stop() can
     // be called before m_workerGlobalScope is fully created.
-    auto locker = tryHoldLock(m_threadCreationAndGlobalScopeLock);
-    if (!locker) {
+    if (!m_threadCreationAndGlobalScopeLock.tryLock()) {
         // The thread is still starting, spin the runloop and try again to avoid deadlocks if the worker thread
         // needs to interact with the main thread during startup.
         callOnMainThread([this, stoppedCallback = WTFMove(stoppedCallback)]() mutable {
@@ -216,6 +215,7 @@
         });
         return;
     }
+    Locker locker { AdoptLock, m_threadCreationAndGlobalScopeLock };
 
     // If the thread is suspended, resume it now so that we can dispatch the cleanup tasks below.
     if (m_isSuspended)

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp (277931 => 277932)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -327,7 +327,7 @@
     if (!decoder->decodedImageCallbackLock.tryLock())
         return;
 
-    Locker locker { AdoptLockTag { }, decoder->decodedImageCallbackLock };
+    Locker locker { AdoptLock, decoder->decodedImageCallbackLock };
 
     if (!decoder->decodedImageCallback)
         return;
@@ -495,7 +495,7 @@
     if (!encoder->encodedImageCallbackLock.tryLock())
         return;
 
-    Locker locker { AdoptLockTag { }, encoder->encodedImageCallbackLock };
+    Locker locker { AdoptLock, encoder->encodedImageCallbackLock };
 
     if (!encoder->encodedImageCallback)
         return;

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp (277931 => 277932)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp	2021-05-23 19:52:22 UTC (rev 277931)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp	2021-05-23 19:55:32 UTC (rev 277932)
@@ -40,7 +40,7 @@
     {
         if (!m_otherLock.tryLock())
             return;
-        Locker holdLock { AdoptLockTag { }, m_otherLock };
+        Locker holdLock { AdoptLock, m_otherLock };
         m_otherValue = value;
     }
     // This function can be used to manually check that compile fails.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to