Skip to content

Commit eb13baf

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Introducing RuntimeScheduler module
Summary: Changelog: [internal[ Introducing RuntimeScheduler. A coordinator of work between native and React. Reviewed By: mdvacca Differential Revision: D27616818 fbshipit-source-id: e90d3d9ca8907be99e61f69e62e83cece8155050
1 parent 5f0bf8b commit eb13baf

File tree

9 files changed

+207
-2
lines changed

9 files changed

+207
-2
lines changed

ReactCommon/React-Fabric.podspec

+9
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ Pod::Spec.new do |s|
336336
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
337337
end
338338

339+
s.subspec "runtimescheduler" do |ss|
340+
ss.dependency folly_dep_name, folly_version
341+
ss.compiler_flags = folly_compiler_flags
342+
ss.source_files = "react/renderer/runtimescheduler/**/*.{cpp,h}"
343+
ss.exclude_files = "react/renderer/runtimescheduler/tests"
344+
ss.header_dir = "react/renderer/runtimescheduler"
345+
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
346+
end
347+
339348
s.subspec "utils" do |ss|
340349
ss.source_files = "react/utils/*.{m,mm,cpp,h}"
341350
ss.header_dir = "react/utils"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
LOCAL_PATH := $(call my-dir)
7+
8+
include $(CLEAR_VARS)
9+
10+
LOCAL_MODULE := react_render_runtimescheduler
11+
12+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../
13+
14+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
15+
16+
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../
17+
18+
LOCAL_SHARED_LIBRARIES := libruntimeexecutor libreact_render_core
19+
20+
LOCAL_CFLAGS := \
21+
-DLOG_TAG=\"Fabric\"
22+
23+
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
24+
25+
include $(BUILD_SHARED_LIBRARY)
26+
27+
$(call import-module,runtimeexecutor)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
load(
2+
"//tools/build_defs/oss:rn_defs.bzl",
3+
"ANDROID",
4+
"APPLE",
5+
"CXX",
6+
"get_apple_compiler_flags",
7+
"get_apple_inspector_flags",
8+
"get_preprocessor_flags_for_build_mode",
9+
"react_native_xplat_target",
10+
"rn_xplat_cxx_library",
11+
"subdir_glob",
12+
)
13+
14+
APPLE_COMPILER_FLAGS = get_apple_compiler_flags()
15+
16+
rn_xplat_cxx_library(
17+
name = "runtimescheduler",
18+
srcs = glob(
19+
["**/*.cpp"],
20+
exclude = glob(["tests/**/*.cpp"]),
21+
),
22+
headers = glob(
23+
["**/*.h"],
24+
exclude = glob(["tests/**/*.h"]),
25+
),
26+
header_namespace = "",
27+
exported_headers = subdir_glob(
28+
[
29+
("", "*.h"),
30+
],
31+
prefix = "react/renderer/runtimescheduler",
32+
),
33+
compiler_flags = [
34+
"-fexceptions",
35+
"-frtti",
36+
"-std=c++17",
37+
"-Wall",
38+
],
39+
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
40+
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
41+
force_static = True,
42+
labels = ["supermodule:xplat/default/public.react_native.infra"],
43+
macosx_tests_override = [],
44+
platforms = (ANDROID, APPLE, CXX),
45+
preprocessor_flags = [
46+
"-DLOG_TAG=\"ReactNative\"",
47+
"-DWITH_FBSYSTRACE=1",
48+
],
49+
visibility = ["PUBLIC"],
50+
deps = [
51+
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
52+
],
53+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "RuntimeScheduler.h"
9+
10+
namespace facebook::react {} // namespace facebook::react
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace facebook {
11+
namespace react {
12+
13+
class RuntimeScheduler final {};
14+
15+
} // namespace react
16+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "RuntimeSchedulerBinding.h"
9+
10+
#include <memory>
11+
12+
namespace facebook::react {
13+
14+
std::shared_ptr<RuntimeSchedulerBinding>
15+
RuntimeSchedulerBinding::createAndInstallIfNeeded(jsi::Runtime &runtime) {
16+
auto runtimeSchedulerModuleName = "nativeRuntimeScheduler";
17+
18+
auto runtimeSchedulerValue =
19+
runtime.global().getProperty(runtime, runtimeSchedulerModuleName);
20+
if (runtimeSchedulerValue.isUndefined()) {
21+
// The global namespace does not have an instance of the binding;
22+
// we need to create, install and return it.
23+
auto runtimeSchedulerBinding = std::make_shared<RuntimeSchedulerBinding>();
24+
auto object =
25+
jsi::Object::createFromHostObject(runtime, runtimeSchedulerBinding);
26+
runtime.global().setProperty(
27+
runtime, runtimeSchedulerModuleName, std::move(object));
28+
return runtimeSchedulerBinding;
29+
}
30+
31+
// The global namespace already has an instance of the binding;
32+
// we need to return that.
33+
auto runtimeSchedulerObject = runtimeSchedulerValue.asObject(runtime);
34+
return runtimeSchedulerObject.getHostObject<RuntimeSchedulerBinding>(runtime);
35+
}
36+
37+
jsi::Value RuntimeSchedulerBinding::get(
38+
jsi::Runtime &runtime,
39+
jsi::PropNameID const &name) {
40+
(void)runtime;
41+
(void)name;
42+
return jsi::Value::undefined();
43+
}
44+
45+
} // namespace facebook::react
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <jsi/jsi.h>
11+
12+
namespace facebook::react {
13+
14+
/*
15+
* Exposes RuntimeScheduler to JavaScript realm.
16+
*/
17+
class RuntimeSchedulerBinding : public jsi::HostObject {
18+
public:
19+
/*
20+
* Installs RuntimeSchedulerBinding into JavaScript runtime if needed.
21+
* Creates and sets `RuntimeSchedulerBinding` into the global namespace.
22+
* In case if the global namespace already has a `RuntimeSchedulerBinding`
23+
* installed, returns that. Thread synchronization must be enforced
24+
* externally.
25+
*/
26+
static std::shared_ptr<RuntimeSchedulerBinding> createAndInstallIfNeeded(
27+
jsi::Runtime &runtime);
28+
29+
/*
30+
* `jsi::HostObject` specific overloads.
31+
*/
32+
jsi::Value get(jsi::Runtime &runtime, jsi::PropNameID const &name) override;
33+
};
34+
35+
} // namespace facebook::react

ReactCommon/react/renderer/scheduler/Android.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
2121

2222
LOCAL_STATIC_LIBRARIES :=
2323

24-
LOCAL_SHARED_LIBRARIES := libyoga librrc_view libreact_utils libreact_render_templateprocessor libreact_render_graphics libreact_render_uimanager libfolly_futures libreact_render_componentregistry glog libreactconfig libfolly_json libjsi libreact_render_core libreact_render_debug librrc_root libreact_render_mounting libreact_debug
24+
LOCAL_SHARED_LIBRARIES := libyoga librrc_view libreact_utils libreact_render_templateprocessor libreact_render_graphics libreact_render_uimanager libfolly_futures libreact_render_componentregistry glog libreactconfig libfolly_json libjsi libreact_render_core libreact_render_debug librrc_root libreact_render_mounting libreact_debug libreact_render_runtimescheduler
2525

2626
include $(BUILD_SHARED_LIBRARY)
2727

@@ -37,6 +37,7 @@ $(call import-module,react/renderer/debug)
3737
$(call import-module,react/renderer/graphics)
3838
$(call import-module,react/renderer/mounting)
3939
$(call import-module,react/renderer/uimanager)
40+
$(call import-module,react/renderer/runtimescheduler)
4041
$(call import-module,react/renderer/templateprocessor)
4142
$(call import-module,react/utils)
4243
$(call import-module,react/debug)

packages/rn-tester/Podfile.lock

+10-1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ PODS:
263263
- React-Fabric/imagemanager (= 1000.0.0)
264264
- React-Fabric/leakchecker (= 1000.0.0)
265265
- React-Fabric/mounting (= 1000.0.0)
266+
- React-Fabric/runtimescheduler (= 1000.0.0)
266267
- React-Fabric/scheduler (= 1000.0.0)
267268
- React-Fabric/telemetry (= 1000.0.0)
268269
- React-Fabric/templateprocessor (= 1000.0.0)
@@ -514,6 +515,14 @@ PODS:
514515
- React-jsi (= 1000.0.0)
515516
- React-jsiexecutor (= 1000.0.0)
516517
- ReactCommon/turbomodule/core (= 1000.0.0)
518+
- React-Fabric/runtimescheduler (1000.0.0):
519+
- RCT-Folly/Fabric (= 2020.01.13.00)
520+
- RCTRequired (= 1000.0.0)
521+
- RCTTypeSafety (= 1000.0.0)
522+
- React-graphics (= 1000.0.0)
523+
- React-jsi (= 1000.0.0)
524+
- React-jsiexecutor (= 1000.0.0)
525+
- ReactCommon/turbomodule/core (= 1000.0.0)
517526
- React-Fabric/scheduler (1000.0.0):
518527
- RCT-Folly/Fabric (= 2020.01.13.00)
519528
- RCTRequired (= 1000.0.0)
@@ -850,7 +859,7 @@ SPEC CHECKSUMS:
850859
React-Core: 2d53d893ddeff7a58e7ed51b43a15a3d94c3c4a7
851860
React-CoreModules: c096a150e14753b07dc68a498508da4e55b026e9
852861
React-cxxreact: 14cce64344ab482615dfe82a2cbea6eb73be6481
853-
React-Fabric: bf713bb8a442b56361b0ed4ca7d070697cc69b38
862+
React-Fabric: 641ddc4b27a2611f483430a043557668fec81bf9
854863
React-graphics: 246b8e6cb4aad51271358767c965e47d692921ab
855864
React-jsi: 08c6628096d2025d4085fbaec8fe14a3c9dc667c
856865
React-jsiexecutor: 896c41b04121803e4ee61e4c9ed0900fdb420fea

0 commit comments

Comments
 (0)