Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c529c6161488dfff930bef950dc71dcbfb9b5e39
      
https://github.com/WebKit/WebKit/commit/c529c6161488dfff930bef950dc71dcbfb9b5e39
  Author: Chris Dumez <[email protected]>
  Date:   2026-04-28 (Tue, 28 Apr 2026)

  Changed paths:
    M Source/WebCore/Modules/webaudio/AudioNode.cpp
    M Source/WebCore/Modules/webaudio/AudioNode.h
    M Source/WebCore/Modules/webaudio/AudioNodeOutput.h
    M Source/WebCore/Modules/webaudio/BaseAudioContext.cpp
    M Source/WebCore/Modules/webaudio/BaseAudioContext.h

  Log Message:
  -----------
  Make AudioNode's ref-counting thread-safe
https://bugs.webkit.org/show_bug.cgi?id=313409

Reviewed by Jer Noble.

AudioNode's ref() and deref() were not safe to call from the audio thread.
deref() had ASSERT(!context().isAudioThread()) and ref() used a blocking
Locker on the graph lock. A protect() override returning CheckedPtr instead
of RefPtr existed as a workaround, but this was error-prone.

This patch makes ref() and deref() safe to call from any thread by using
the same tryLock/defer pattern already used by decrementConnectionCount():
on the audio thread, tryLock the graph lock to avoid glitches; if the lock
can't be acquired, defer the work to handlePostRenderTasks(). On the main
thread, use a blocking lock as before.

With thread-safe ref-counting, the protect() override returning CheckedPtr
is no longer needed — protect() now returns RefPtr for AudioNodes like any
other ref-counted type. AudioNodeOutput::context() is a special case that
uses CheckedPtr directly to avoid ref/deref side effects that would cause
deep recursion during markNodeForDeletionIfNecessary() → disconnectAll()
chains.

* Source/WebCore/Modules/webaudio/AudioNode.cpp:
(WebCore::AudioNode::ref const):
(WebCore::AudioNode::deref const):
* Source/WebCore/Modules/webaudio/AudioNode.h:
(WebCore::AudioNode::clearIsMarkedForDeletion):
(WebCore::AudioNode::hasReferences const):
(WTF::protect): Deleted.
* Source/WebCore/Modules/webaudio/AudioNodeOutput.h:
* Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:
(WebCore::BaseAudioContext::uninitialize):
(WebCore::BaseAudioContext::addDeferredDeref):
(WebCore::BaseAudioContext::handlePostRenderTasks):
(WebCore::BaseAudioContext::handleDeferredDecrementConnectionCounts):
(WebCore::BaseAudioContext::handleDeferredDerefs):
(WebCore::BaseAudioContext::deleteMarkedNodes):
* Source/WebCore/Modules/webaudio/BaseAudioContext.h:

Canonical link: https://commits.webkit.org/312187@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to