Skip to content

Make Node::owner_ a relaxed atomic pointer (#2094) - #60405

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
javache:export-D135070417
Nov 30, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
javache:export-D135070417

Conversation

@javache

@javache javache commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • Make Node::owner_ a relaxed atomic pointer

A Yoga node shared between two trees can have its owner read by a layout
pass on one thread while a clone of its previous owner on another thread
rewrites it. owner_ was a plain pointer, so that is a data race. Loads and
stores of the owner now use std::atomic with relaxed ordering, through a
small copyable wrapper so Node keeps its defaulted copy operations.

  • Keep RelaxedAtomicPointer private to Node and test owner access

Moves the RelaxedAtomicPointer helper into Node's private section so it is not
part of the facebook::yoga namespace, and adds tests for reading a node's owner
while another thread sets it, and for the owner after copying, moving, cloning
the parent and resetting.

  • Free the shared child in cloned_parent_keeps_shared_child_owner

YGNodeFree(clone) clears the shared child's owner, so
YGNodeFreeRecursive(parent) skips it and the child leaks.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com


Reviewed By: javache

Differential Revision: D135070417

Summary:
* Make Node::owner_ a relaxed atomic pointer

A Yoga node shared between two trees can have its owner read by a layout
pass on one thread while a clone of its previous owner on another thread
rewrites it. owner_ was a plain pointer, so that is a data race. Loads and
stores of the owner now use std::atomic with relaxed ordering, through a
small copyable wrapper so Node keeps its defaulted copy operations.

* Keep RelaxedAtomicPointer private to Node and test owner access

Moves the RelaxedAtomicPointer helper into Node's private section so it is not
part of the facebook::yoga namespace, and adds tests for reading a node's owner
while another thread sets it, and for the owner after copying, moving, cloning
the parent and resetting.

* Free the shared child in cloned_parent_keeps_shared_child_owner

YGNodeFree(clone) clears the shared child's owner, so
YGNodeFreeRecursive(parent) skips it and the child leaks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Reviewed By: javache

Differential Revision: D135070417
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2026
@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135070417.

@meta-codesync
meta-codesync Bot merged commit 774eb72 into react:main Nov 30, 2026
63 of 70 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @javache in 774eb72

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants