Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: bca037abbb7d0977175b2cc6207e7c183a43d967
https://github.com/WebKit/WebKit/commit/bca037abbb7d0977175b2cc6207e7c183a43d967
Author: Chris Dumez <[email protected]>
Date: 2026-03-30 (Mon, 30 Mar 2026)
Changed paths:
M Source/WTF/wtf/CheckedRef.h
Log Message:
-----------
Relax memory ordering for CanMakeThreadSafeCheckedPtr atomic operations
https://bugs.webkit.org/show_bug.cgi?id=310854
Reviewed by Geoffrey Garen.
CanMakeCheckedPtrBase used seq_cst (the default for std::atomic operators)
for all checked pointer count operations. This is stronger than necessary.
The checked pointer count is a diagnostic counter for zombie detection, not
a reference count that guards data access or triggers deallocation.
Use the same memory ordering strategy proven by std::shared_ptr and
Boost.Atomic for reference counting:
- Increment: memory_order_relaxed. A new CheckedPtr/CheckedRef can only be
created from an existing reference, and communicating that reference across
threads already provides the necessary synchronization. This is the same
argument that makes relaxed safe for std::shared_ptr increments.
- Decrement: memory_order_release. The release ensures that all prior
accesses through the CheckedPtr happen-before the count drops. Unlike
std::shared_ptr, the decrement never triggers destruction, so the acquire
side is not needed on the decrement itself. The destroying delete path
reads the count via checkedPtrCountWithoutThreadCheck() which uses
memory_order_acquire, forming a valid release/acquire pair.
- Read (checkedPtrCountWithoutThreadCheck): memory_order_acquire. This
synchronizes with release decrements so the destroying delete path
reliably sees all outstanding references when deciding whether to enter
the zombie path.
On ARM64, this replaces full memory barriers (dmb ish) with lighter
instructions: relaxed increment becomes a plain ldadd, release decrement
becomes stlr/ldaddl, and acquire load becomes ldar.
Also introduces an AtomicLike concept to dispatch between atomic and
non-atomic storage, replacing the previous `std::is_same_v<StorageType,
std::atomic<uint32_t>>` check. This is more expressive (describes the
required interface rather than a specific type) and would work with any
atomic-like wrapper, not just `std::atomic<uint32_t>`.
No behavior change for the single-threaded CanMakeCheckedPtr path, which
continues to use plain integer operations with thread assertions.
* Source/WTF/wtf/CheckedRef.h:
(WTF::requires):
(WTF::CanMakeCheckedPtrBase::incrementCheckedPtrCount const):
(WTF::CanMakeCheckedPtrBase::decrementCheckedPtrCount const):
(WTF::CanMakeCheckedPtrBase::checkedPtrCountWithoutThreadCheck const):
Canonical link: https://commits.webkit.org/310266@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications