Skip to content

Commit 821045a

Browse files
Yqwedreact-native-bot
authored andcommitted
Do not synchronize on java.lang.Boolean. (#56196)
Summary: ## Summary: Do not synchronize on java.lang.Boolean. Once JEP 401 is implemented synchronization on value classes (which box classes are) will throw IdentityException. In general synchronization on 1) mutable field 2) box class is inefficient (instances are shared) at best and a bug at worst case as synchronization is done holding different monitors (it might be fine, but is hard to reason about). ## Changelog: [ANDROID] [FIXED] Use explicit `ReactInstanceManager.mHasStartedDestroyingLock` instead of using `ReactInstanceManager.mHasStartedDestroying` <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #56196 Test Plan: GHA Reviewed By: cortinico Differential Revision: D110168816 Pulled By: javache fbshipit-source-id: dae081dc00a94859f19dcc3607971a9c3d6fbd44
1 parent 36f69ef commit 821045a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public interface ReactInstanceEventListener
171171
// Identifies whether the instance manager destroy function is in process,
172172
// while true any spawned create thread should wait for proper clean up before initializing
173173
private volatile Boolean mHasStartedDestroying = false;
174+
private final Object mHasStartedDestroyingLock = new Object();
174175
private final MemoryPressureRouter mMemoryPressureRouter;
175176
private final @Nullable JSExceptionHandler mJSExceptionHandler;
176177
private final @Nullable UIManagerProvider mUIManagerProvider;
@@ -782,8 +783,8 @@ public void destroy() {
782783
ResourceDrawableIdHelper.getInstance().clear();
783784

784785
mHasStartedDestroying = false;
785-
synchronized (mHasStartedDestroying) {
786-
mHasStartedDestroying.notifyAll();
786+
synchronized (mHasStartedDestroyingLock) {
787+
mHasStartedDestroyingLock.notifyAll();
787788
}
788789
synchronized (mPackages) {
789790
mViewManagerNames = null;
@@ -1139,10 +1140,10 @@ private void runCreateReactContextOnNewThread(final ReactContextInitParams initP
11391140
null,
11401141
() -> {
11411142
ReactMarker.logMarker(REACT_CONTEXT_THREAD_END);
1142-
synchronized (ReactInstanceManager.this.mHasStartedDestroying) {
1143+
synchronized (ReactInstanceManager.this.mHasStartedDestroyingLock) {
11431144
while (ReactInstanceManager.this.mHasStartedDestroying) {
11441145
try {
1145-
ReactInstanceManager.this.mHasStartedDestroying.wait();
1146+
ReactInstanceManager.this.mHasStartedDestroyingLock.wait();
11461147
} catch (InterruptedException e) {
11471148
// Interrupted while waiting for destruction to complete, just retry
11481149
continue;

0 commit comments

Comments
 (0)