Skip to content

Commit 88bc348

Browse files
committed
Use ThreadScope::WithClassLoader in setupFuture call
1 parent 217ba59 commit 88bc348

File tree

3 files changed

+100
-101
lines changed

3 files changed

+100
-101
lines changed

android/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4.1)
22

33
set (CMAKE_VERBOSE_MAKEFILE ON)
44
set (CMAKE_CXX_STANDARD 14)
5-
set (CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1")
5+
set (CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID")
66

77
set (PACKAGE_NAME "rnmultithreading")
88
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

android/src/main/cpp/cpp-adapter.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,12 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
3131

3232
private:
3333
static std::shared_ptr<react::JSExecutorFactory> makeJSExecutorFactory() {
34-
std::shared_ptr<react::JSExecutorFactory> factory;
35-
36-
ThreadScope::WithClassLoader([&factory]() {
37-
__android_log_write(ANDROID_LOG_INFO, TAG, "Calling Java method MultithreadingModule.makeJSExecutor()...");
38-
static const auto cls = javaClassStatic();
39-
static const auto method = cls->getStaticMethod<react::JavaScriptExecutorHolder()>("makeJSExecutor");
40-
auto result = method(cls);
41-
__android_log_write(ANDROID_LOG_INFO, TAG, "JavaScriptExecutor created! Getting factory...");
42-
auto cxxInstance = result->cthis()->getExecutorFactory();
43-
factory = cxxInstance;
44-
});
45-
if (factory == nullptr) {
46-
throw std::runtime_error("Failed to create the JSExecutorFactory! shared_ptr was null.");
47-
}
48-
49-
return factory;
34+
__android_log_write(ANDROID_LOG_INFO, TAG, "Calling Java method MultithreadingModule.makeJSExecutor()...");
35+
static const auto cls = javaClassStatic();
36+
static const auto method = cls->getStaticMethod<react::JavaScriptExecutorHolder()>("makeJSExecutor");
37+
auto result = method(cls);
38+
__android_log_write(ANDROID_LOG_INFO, TAG, "JavaScriptExecutor created! Getting factory...");
39+
return result->cthis()->getExecutorFactory();
5040
}
5141

5242
static void installNative(jni::alias_ref<JClass>,
@@ -69,9 +59,6 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
6959
auto makeJsExecutor = []() -> std::unique_ptr<jsi::Runtime> {
7060
__android_log_write(ANDROID_LOG_INFO, TAG, "Creating JSExecutorFactory..");
7161
try {
72-
// JNI needs to attach this thread because this function is being called from a different Thread
73-
__unused ThreadScope scope; // RAII
74-
7562
std::shared_ptr<react::ExecutorDelegate> delegate = std::shared_ptr<react::ExecutorDelegate>();
7663
std::shared_ptr<react::MessageQueueThread> jsQueue = std::shared_ptr<react::MessageQueueThread>();
7764

0 commit comments

Comments
 (0)