diff --git a/java/com/facebook/soloader/nativeloader/NativeLoader.java b/java/com/facebook/soloader/nativeloader/NativeLoader.java index 04f2d6d..ec33b2b 100644 --- a/java/com/facebook/soloader/nativeloader/NativeLoader.java +++ b/java/com/facebook/soloader/nativeloader/NativeLoader.java @@ -48,6 +48,7 @@ public static boolean loadLibrary(String shortName, int flags) { + "NativeLoader.init(new SystemDelegate())."); } } + return sDelegate.loadLibrary(shortName, flags); } @@ -95,11 +96,13 @@ public static int getSoSourcesVersion() { * * @param delegate Delegate to use for all {@code loadLibrary} calls. */ - public static synchronized void init(NativeLoaderDelegate delegate) { - if (sDelegate != null) { - throw new IllegalStateException("Cannot re-initialize NativeLoader."); + public static void init(NativeLoaderDelegate delegate) { + synchronized (NativeLoader.class) { + if (sDelegate != null) { + throw new IllegalStateException("Cannot re-initialize NativeLoader."); + } + sDelegate = delegate; } - sDelegate = delegate; } /** @@ -110,8 +113,10 @@ public static synchronized void init(NativeLoaderDelegate delegate) { * * @return True if {@link #init(NativeLoaderDelegate)} has been called. */ - public static synchronized boolean isInitialized() { - return sDelegate != null; + public static boolean isInitialized() { + synchronized (NativeLoader.class) { + return sDelegate != null; + } } /** @@ -121,7 +126,7 @@ public static synchronized boolean isInitialized() { * * @param delegate the NativeLoaderDelegate */ - public static synchronized void initIfUninitialized(NativeLoaderDelegate delegate) { + public static void initIfUninitialized(NativeLoaderDelegate delegate) { if (!isInitialized()) { init(delegate); }