From 2f92ee8a9cb95f6e67e25f2ed9061e1e255666bf Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 20 Mar 2017 05:57:48 -0700 Subject: [PATCH] Attempt to fix CircleCI tests Summary: Attempt to always call `mBridgeIdleListeners` on the native modules thread mBridgeIdleListeners Closes https://github.com/facebook/react-native/pull/13004 Differential Revision: D4734342 Pulled By: mkonicek fbshipit-source-id: f7054015a1d4517abab9bb8fc61402efabdd6ac1 --- .../react/cxxbridge/CatalystInstanceImpl.java | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java index 6133b2576..81f2773be 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java @@ -93,6 +93,7 @@ public class CatalystInstanceImpl implements CatalystInstance { private final NativeModuleRegistry mJavaRegistry; private final NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler; + private final MessageQueueThread mNativeModulesQueueThread; private boolean mInitialized = false; private volatile boolean mAcceptCalls = false; @@ -121,6 +122,7 @@ public class CatalystInstanceImpl implements CatalystInstance { mJSModuleRegistry = jsModuleRegistry; mJSBundleLoader = jsBundleLoader; mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler; + mNativeModulesQueueThread = mReactQueueConfiguration.getNativeModulesQueueThread(); mTraceListener = new JSProfilerTraceListener(this); FLog.w(ReactConstants.TAG, "Initializing React Xplat Bridge before initializeBridge"); @@ -128,7 +130,7 @@ public class CatalystInstanceImpl implements CatalystInstance { new BridgeCallback(this), jsExecutor, mReactQueueConfiguration.getJSQueueThread(), - mReactQueueConfiguration.getNativeModulesQueueThread(), + mNativeModulesQueueThread, mJavaRegistry.getJavaModules(this), mJavaRegistry.getCxxModules()); FLog.w(ReactConstants.TAG, "Initializing React Xplat Bridge after initializeBridge"); @@ -292,19 +294,19 @@ public class CatalystInstanceImpl implements CatalystInstance { // TODO: tell all APIs to shut down mDestroyed = true; - mReactQueueConfiguration.getNativeModulesQueueThread().runOnQueue(new Runnable() { + mNativeModulesQueueThread.runOnQueue(new Runnable() { @Override public void run() { mJavaRegistry.notifyJSInstanceDestroy(); + boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0); + if (!wasIdle && !mBridgeIdleListeners.isEmpty()) { + for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { + listener.onTransitionToBridgeIdle(); + } + } mHybridData.resetNative(); } }); - boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0); - if (!wasIdle && !mBridgeIdleListeners.isEmpty()) { - for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { - listener.onTransitionToBridgeIdle(); - } - } // This is a noop if the listener was not yet registered. Systrace.unregisterListener(mTraceListener); @@ -332,7 +334,7 @@ public class CatalystInstanceImpl implements CatalystInstance { mAcceptCalls, "RunJSBundle hasn't completed."); mInitialized = true; - mReactQueueConfiguration.getNativeModulesQueueThread().runOnQueue(new Runnable() { + mNativeModulesQueueThread.runOnQueue(new Runnable() { @Override public void run() { mJavaRegistry.notifyJSInstanceInitialized(); @@ -442,9 +444,14 @@ public class CatalystInstanceImpl implements CatalystInstance { mJsPendingCallsTitleForTrace, oldPendingCalls + 1); if (wasIdle && !mBridgeIdleListeners.isEmpty()) { - for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { - listener.onTransitionToBridgeBusy(); - } + mNativeModulesQueueThread.runOnQueue(new Runnable() { + @Override + public void run() { + for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { + listener.onTransitionToBridgeBusy(); + } + } + }); } } @@ -459,9 +466,14 @@ public class CatalystInstanceImpl implements CatalystInstance { newPendingCalls); if (isNowIdle && !mBridgeIdleListeners.isEmpty()) { - for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { - listener.onTransitionToBridgeIdle(); - } + mNativeModulesQueueThread.runOnQueue(new Runnable() { + @Override + public void run() { + for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { + listener.onTransitionToBridgeIdle(); + } + } + }); } }