mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Hopefully fix so loading crashes
Summary: Changelog: [Android][Internal] Fix potential initializer interruption threading crashes. Reviewed By: mdvacca Differential Revision: D20615755 fbshipit-source-id: 58b706deeb6df1998caff5bf2ae9ec60114313fe
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d241de9cb4
commit
33f20242f6
+10
-3
@@ -17,13 +17,20 @@ import com.facebook.soloader.SoLoader;
|
||||
* pass it from CatalystInstance, through Java, to TurboModuleManager::initHybrid.
|
||||
*/
|
||||
public class CallInvokerHolderImpl implements CallInvokerHolder {
|
||||
static {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
}
|
||||
private static volatile boolean sIsSoLibraryLoaded;
|
||||
|
||||
private final HybridData mHybridData;
|
||||
|
||||
private CallInvokerHolderImpl(HybridData hd) {
|
||||
maybeLoadSoLibrary();
|
||||
mHybridData = hd;
|
||||
}
|
||||
|
||||
// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
|
||||
private static synchronized void maybeLoadSoLibrary() {
|
||||
if (!sIsSoLibraryLoaded) {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
sIsSoLibraryLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -26,11 +26,9 @@ import java.util.*;
|
||||
* a Java module, that the C++ counterpart calls.
|
||||
*/
|
||||
public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
|
||||
static {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
}
|
||||
|
||||
private final TurboModuleManagerDelegate mTurbomoduleManagerDelegate;
|
||||
private static volatile boolean sIsSoLibraryLoaded;
|
||||
|
||||
private final Map<String, TurboModule> mTurboModules = new HashMap<>();
|
||||
|
||||
@@ -43,6 +41,7 @@ public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
|
||||
TurboModuleManagerDelegate tmmDelegate,
|
||||
CallInvokerHolder jsCallInvokerHolder,
|
||||
CallInvokerHolder nativeCallInvokerHolder) {
|
||||
maybeLoadSoLibrary();
|
||||
mHybridData =
|
||||
initHybrid(
|
||||
jsContext.get(),
|
||||
@@ -137,4 +136,12 @@ public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
|
||||
// Delete the native part of this hybrid class.
|
||||
mHybridData.resetNative();
|
||||
}
|
||||
|
||||
// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
|
||||
private static synchronized void maybeLoadSoLibrary() {
|
||||
if (!sIsSoLibraryLoaded) {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
sIsSoLibraryLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-4
@@ -16,15 +16,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TurboModuleManagerDelegate {
|
||||
static {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
}
|
||||
|
||||
private final HybridData mHybridData;
|
||||
|
||||
private static volatile boolean sIsSoLibraryLoaded;
|
||||
|
||||
protected abstract HybridData initHybrid();
|
||||
|
||||
protected TurboModuleManagerDelegate() {
|
||||
maybeLoadOtherSoLibraries();
|
||||
maybeLoadSoLibrary();
|
||||
mHybridData = initHybrid();
|
||||
}
|
||||
|
||||
@@ -45,4 +45,14 @@ public abstract class TurboModuleManagerDelegate {
|
||||
public List<String> getEagerInitModuleNames() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
|
||||
private static synchronized void maybeLoadSoLibrary() {
|
||||
if (!sIsSoLibraryLoaded) {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
sIsSoLibraryLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized void maybeLoadOtherSoLibraries() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user