Reduce possible race condition on gc of catalyst instance

Reviewed By: cwdick

Differential Revision: D5669579

fbshipit-source-id: 165e19b68199e89bb99f7f93f2b1ec70729b2848
This commit is contained in:
Kathy Gray 2017-08-22 03:28:36 -07:00 committed by Facebook Github Bot
parent 5cdf5f3910
commit f0d98104ae
3 changed files with 9 additions and 0 deletions

View File

@ -329,6 +329,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
quitQueuesSynchronous();
mHybridData.resetNative();
// Kill non-UI threads from UI thread.
getReactQueueConfiguration().destroy();
@ -342,6 +343,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
Systrace.unregisterListener(mTraceListener);
}
private native void quitQueuesSynchronous();
@Override
public boolean isDestroyed() {
return mDestroyed;

View File

@ -85,6 +85,9 @@ CatalystInstanceImpl::CatalystInstanceImpl()
: instance_(folly::make_unique<Instance>()) {}
CatalystInstanceImpl::~CatalystInstanceImpl() {
}
void CatalystInstanceImpl::quitQueuesSynchronous() {
moduleMessageQueue_->quitSynchronous();
if (uiBackgroundMessageQueue_ != NULL) {
uiBackgroundMessageQueue_->quitSynchronous();
@ -95,6 +98,7 @@ void CatalystInstanceImpl::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", CatalystInstanceImpl::initHybrid),
makeNativeMethod("initializeBridge", CatalystInstanceImpl::initializeBridge),
makeNativeMethod("quitQueuesSynchronous", CatalystInstanceImpl::quitQueuesSynchronous),
makeNativeMethod("jniExtendNativeModules", CatalystInstanceImpl::extendNativeModules),
makeNativeMethod("jniSetSourceURL", CatalystInstanceImpl::jniSetSourceURL),
makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets),

View File

@ -35,6 +35,8 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
return instance_;
}
void quitQueuesSynchronous();
private:
friend HybridBase;