⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278285 in webkit


Ignore:
Timestamp:
May 31, 2021, 5:03:36 PM (5 years ago)
Author:
Chris Dumez
Message:

Fix thread safety issues in OscillatorNode
https://bugs.webkit.org/show_bug.cgi?id=226450

Reviewed by Darin Adler.

Adopt thread safety annotations in OscillatorNode and fix bugs found by clang.
In particular, propagatesSilence() was failing to grab the lock before accessing
m_periodicWave, which gets modified on the main thread.

  • Modules/webaudio/OscillatorNode.cpp:

(WebCore::OscillatorNode::create):
(WebCore::OscillatorNode::setTypeForBindings):
(WebCore::OscillatorNode::propagatesSilence const):

  • Modules/webaudio/OscillatorNode.h:
  • Modules/webaudio/OscillatorNode.idl:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278284 r278285  
     12021-05-31  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix thread safety issues in OscillatorNode
     4        https://bugs.webkit.org/show_bug.cgi?id=226450
     5
     6        Reviewed by Darin Adler.
     7
     8        Adopt thread safety annotations in OscillatorNode and fix bugs found by clang.
     9        In particular, propagatesSilence() was failing to grab the lock before accessing
     10        m_periodicWave, which gets modified on the main thread.
     11
     12        * Modules/webaudio/OscillatorNode.cpp:
     13        (WebCore::OscillatorNode::create):
     14        (WebCore::OscillatorNode::setTypeForBindings):
     15        (WebCore::OscillatorNode::propagatesSilence const):
     16        * Modules/webaudio/OscillatorNode.h:
     17        * Modules/webaudio/OscillatorNode.idl:
     18
    1192021-05-31  Chris Dumez  <cdumez@apple.com>
    220
  • trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp

    r277932 r278285  
    7373        oscillator->setPeriodicWave(*options.periodicWave);
    7474    else {
    75         result = oscillator->setType(options.type);
     75        result = oscillator->setTypeForBindings(options.type);
    7676        if (result.hasException())
    7777            return result.releaseException();
     
    9898}
    9999
    100 ExceptionOr<void> OscillatorNode::setType(OscillatorType type)
     100ExceptionOr<void> OscillatorNode::setTypeForBindings(OscillatorType type)
    101101{
    102102    ALWAYS_LOG(LOGIDENTIFIER, type);
     103    ASSERT(isMainThread());
    103104
    104105    if (type == OscillatorType::Custom) {
     
    439440bool OscillatorNode::propagatesSilence() const
    440441{
    441     return !isPlayingOrScheduled() || hasFinished() || !m_periodicWave.get();
     442    ASSERT(context().isAudioThread());
     443    if (!isPlayingOrScheduled() || hasFinished())
     444        return true;
     445    if (!m_processLock.tryLock())
     446        return false; // Assume we have a periodic wave if we are unable to grab the lock.
     447    Locker locker { AdoptLock, m_processLock };
     448    return !m_periodicWave.get();
    442449}
    443450
  • trunk/Source/WebCore/Modules/webaudio/OscillatorNode.h

    r277530 r278285  
    4545    const char* activeDOMObjectName() const final { return "OscillatorNode"; }
    4646
    47     OscillatorType type() const { return m_type; }
    48     ExceptionOr<void> setType(OscillatorType);
     47    OscillatorType typeForBindings() const { ASSERT(isMainThread()); return m_type; }
     48    ExceptionOr<void> setTypeForBindings(OscillatorType);
    4949
    5050    AudioParam* frequency() { return m_frequency.get(); }
     
    6363
    6464    // Returns true if there are sample-accurate timeline parameter changes.
    65     bool calculateSampleAccuratePhaseIncrements(size_t framesToProcess);
     65    bool calculateSampleAccuratePhaseIncrements(size_t framesToProcess) WTF_REQUIRES_LOCK(m_processLock);
    6666
    67     double processARate(int, float* destP, double virtualReadIndex, float* phaseIncrements);
    68     double processKRate(int, float* destP, double virtualReadIndex);
     67    double processARate(int, float* destP, double virtualReadIndex, float* phaseIncrements) WTF_REQUIRES_LOCK(m_processLock);
     68    double processKRate(int, float* destP, double virtualReadIndex) WTF_REQUIRES_LOCK(m_processLock);
    6969
    7070    bool propagatesSilence() const final;
    7171
    7272    // One of the waveform types defined in the enum.
    73     OscillatorType m_type;
     73    OscillatorType m_type; // Only used on the main thread.
    7474   
    7575    // Frequency value in Hertz.
     
    9292    AudioFloatArray m_detuneValues;
    9393   
    94     RefPtr<PeriodicWave> m_periodicWave;
     94    RefPtr<PeriodicWave> m_periodicWave WTF_GUARDED_BY_LOCK(m_processLock);
    9595};
    9696
  • trunk/Source/WebCore/Modules/webaudio/OscillatorNode.idl

    r277530 r278285  
    3232    [EnabledBySetting=WebAudio] constructor (BaseAudioContext context, optional OscillatorOptions options);
    3333
    34     attribute OscillatorType type;
     34    [ImplementedAs=typeForBindings] attribute OscillatorType type;
    3535
    3636    readonly attribute AudioParam frequency; // in Hertz
Note: See TracChangeset for help on using the changeset viewer.