Skip to content

Commit

Permalink
Reduce possible race condition on gc of catalyst instance
Browse files Browse the repository at this point in the history
Reviewed By: cwdick

Differential Revision: D5669579

fbshipit-source-id: 165e19b68199e89bb99f7f93f2b1ec70729b2848
  • Loading branch information
Kathy Gray authored and facebook-github-bot committed Aug 22, 2017
1 parent 5cdf5f3 commit f0d9810
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public void run() {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
quitQueuesSynchronous();
mHybridData.resetNative();
// Kill non-UI threads from UI thread.
getReactQueueConfiguration().destroy();
Expand All @@ -342,6 +343,8 @@ public void run() {
Systrace.unregisterListener(mTraceListener);
}

private native void quitQueuesSynchronous();

@Override
public boolean isDestroyed() {
return mDestroyed;
Expand Down
4 changes: 4 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ CatalystInstanceImpl::CatalystInstanceImpl()
: instance_(folly::make_unique<Instance>()) {}

CatalystInstanceImpl::~CatalystInstanceImpl() {
}

void CatalystInstanceImpl::quitQueuesSynchronous() {
moduleMessageQueue_->quitSynchronous();
if (uiBackgroundMessageQueue_ != NULL) {
uiBackgroundMessageQueue_->quitSynchronous();
Expand All @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
return instance_;
}

void quitQueuesSynchronous();

private:
friend HybridBase;

Expand Down

0 comments on commit f0d9810

Please sign in to comment.