Skip to content

Commit

Permalink
Back out "Make NativeModules immediately initializable"
Browse files Browse the repository at this point in the history
Summary:
This caused a few apps to crash on launch.

Changelog: [Android][Fixed] - Crashes due to "Make NativeModules immediately initializable"

Reviewed By: olegbl

Differential Revision: D26278594

fbshipit-source-id: 969a3dc49a843366c4ae6ed19a9233d1e6f39b13
  • Loading branch information
fatalsun authored and facebook-github-bot committed Feb 5, 2021
1 parent a70dc4b commit b474be6
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ModuleHolder {
private @Nullable @GuardedBy("this") NativeModule mModule;

// These are used to communicate phases of creation and initialization across threads
private @GuardedBy("this") boolean mInitializable;
private @GuardedBy("this") boolean mIsCreating;
private @GuardedBy("this") boolean mIsInitializing;

Expand Down Expand Up @@ -88,6 +89,7 @@ public ModuleHolder(NativeModule nativeModule) {
boolean shouldInitializeNow = false;
NativeModule module = null;
synchronized (this) {
mInitializable = true;
if (mModule != null) {
Assertions.assertCondition(!mIsInitializing);
shouldInitializeNow = true;
Expand Down Expand Up @@ -191,7 +193,7 @@ private NativeModule create() {
boolean shouldInitializeNow = false;
synchronized (this) {
mModule = module;
if (!mIsInitializing) {
if (mInitializable && !mIsInitializing) {
shouldInitializeNow = true;
}
}
Expand Down Expand Up @@ -225,7 +227,7 @@ private void doInitialize(NativeModule module) {
boolean shouldInitialize = false;
// Check to see if another thread is initializing the object, if not claim the responsibility
synchronized (this) {
if (!mIsInitializing) {
if (mInitializable && !mIsInitializing) {
shouldInitialize = true;
mIsInitializing = true;
}
Expand Down

0 comments on commit b474be6

Please sign in to comment.