Skip to content

Commit

Permalink
Introducing RuntimeScheduler module
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal[

Introducing RuntimeScheduler. A coordinator of work between native and React.

Reviewed By: mdvacca

Differential Revision: D27616818

fbshipit-source-id: e90d3d9ca8907be99e61f69e62e83cece8155050
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Apr 8, 2021
1 parent 5f0bf8b commit eb13baf
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ Pod::Spec.new do |s|
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
end

s.subspec "runtimescheduler" do |ss|
ss.dependency folly_dep_name, folly_version
ss.compiler_flags = folly_compiler_flags
ss.source_files = "react/renderer/runtimescheduler/**/*.{cpp,h}"
ss.exclude_files = "react/renderer/runtimescheduler/tests"
ss.header_dir = "react/renderer/runtimescheduler"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
end

s.subspec "utils" do |ss|
ss.source_files = "react/utils/*.{m,mm,cpp,h}"
ss.header_dir = "react/utils"
Expand Down
27 changes: 27 additions & 0 deletions ReactCommon/react/renderer/runtimescheduler/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := react_render_runtimescheduler

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../

LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../

LOCAL_SHARED_LIBRARIES := libruntimeexecutor libreact_render_core

LOCAL_CFLAGS := \
-DLOG_TAG=\"Fabric\"

LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall

include $(BUILD_SHARED_LIBRARY)

$(call import-module,runtimeexecutor)
53 changes: 53 additions & 0 deletions ReactCommon/react/renderer/runtimescheduler/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
load(
"//tools/build_defs/oss:rn_defs.bzl",
"ANDROID",
"APPLE",
"CXX",
"get_apple_compiler_flags",
"get_apple_inspector_flags",
"get_preprocessor_flags_for_build_mode",
"react_native_xplat_target",
"rn_xplat_cxx_library",
"subdir_glob",
)

APPLE_COMPILER_FLAGS = get_apple_compiler_flags()

rn_xplat_cxx_library(
name = "runtimescheduler",
srcs = glob(
["**/*.cpp"],
exclude = glob(["tests/**/*.cpp"]),
),
headers = glob(
["**/*.h"],
exclude = glob(["tests/**/*.h"]),
),
header_namespace = "",
exported_headers = subdir_glob(
[
("", "*.h"),
],
prefix = "react/renderer/runtimescheduler",
),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++17",
"-Wall",
],
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
force_static = True,
labels = ["supermodule:xplat/default/public.react_native.infra"],
macosx_tests_override = [],
platforms = (ANDROID, APPLE, CXX),
preprocessor_flags = [
"-DLOG_TAG=\"ReactNative\"",
"-DWITH_FBSYSTRACE=1",
],
visibility = ["PUBLIC"],
deps = [
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
],
)
10 changes: 10 additions & 0 deletions ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "RuntimeScheduler.h"

namespace facebook::react {} // namespace facebook::react
16 changes: 16 additions & 0 deletions ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

namespace facebook {
namespace react {

class RuntimeScheduler final {};

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "RuntimeSchedulerBinding.h"

#include <memory>

namespace facebook::react {

std::shared_ptr<RuntimeSchedulerBinding>
RuntimeSchedulerBinding::createAndInstallIfNeeded(jsi::Runtime &runtime) {
auto runtimeSchedulerModuleName = "nativeRuntimeScheduler";

auto runtimeSchedulerValue =
runtime.global().getProperty(runtime, runtimeSchedulerModuleName);
if (runtimeSchedulerValue.isUndefined()) {
// The global namespace does not have an instance of the binding;
// we need to create, install and return it.
auto runtimeSchedulerBinding = std::make_shared<RuntimeSchedulerBinding>();
auto object =
jsi::Object::createFromHostObject(runtime, runtimeSchedulerBinding);
runtime.global().setProperty(
runtime, runtimeSchedulerModuleName, std::move(object));
return runtimeSchedulerBinding;
}

// The global namespace already has an instance of the binding;
// we need to return that.
auto runtimeSchedulerObject = runtimeSchedulerValue.asObject(runtime);
return runtimeSchedulerObject.getHostObject<RuntimeSchedulerBinding>(runtime);
}

jsi::Value RuntimeSchedulerBinding::get(
jsi::Runtime &runtime,
jsi::PropNameID const &name) {
(void)runtime;
(void)name;
return jsi::Value::undefined();
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <jsi/jsi.h>

namespace facebook::react {

/*
* Exposes RuntimeScheduler to JavaScript realm.
*/
class RuntimeSchedulerBinding : public jsi::HostObject {
public:
/*
* Installs RuntimeSchedulerBinding into JavaScript runtime if needed.
* Creates and sets `RuntimeSchedulerBinding` into the global namespace.
* In case if the global namespace already has a `RuntimeSchedulerBinding`
* installed, returns that. Thread synchronization must be enforced
* externally.
*/
static std::shared_ptr<RuntimeSchedulerBinding> createAndInstallIfNeeded(
jsi::Runtime &runtime);

/*
* `jsi::HostObject` specific overloads.
*/
jsi::Value get(jsi::Runtime &runtime, jsi::PropNameID const &name) override;
};

} // namespace facebook::react
3 changes: 2 additions & 1 deletion ReactCommon/react/renderer/scheduler/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall

LOCAL_STATIC_LIBRARIES :=

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
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

include $(BUILD_SHARED_LIBRARY)

Expand All @@ -37,6 +37,7 @@ $(call import-module,react/renderer/debug)
$(call import-module,react/renderer/graphics)
$(call import-module,react/renderer/mounting)
$(call import-module,react/renderer/uimanager)
$(call import-module,react/renderer/runtimescheduler)
$(call import-module,react/renderer/templateprocessor)
$(call import-module,react/utils)
$(call import-module,react/debug)
Expand Down
11 changes: 10 additions & 1 deletion packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ PODS:
- React-Fabric/imagemanager (= 1000.0.0)
- React-Fabric/leakchecker (= 1000.0.0)
- React-Fabric/mounting (= 1000.0.0)
- React-Fabric/runtimescheduler (= 1000.0.0)
- React-Fabric/scheduler (= 1000.0.0)
- React-Fabric/telemetry (= 1000.0.0)
- React-Fabric/templateprocessor (= 1000.0.0)
Expand Down Expand Up @@ -514,6 +515,14 @@ PODS:
- React-jsi (= 1000.0.0)
- React-jsiexecutor (= 1000.0.0)
- ReactCommon/turbomodule/core (= 1000.0.0)
- React-Fabric/runtimescheduler (1000.0.0):
- RCT-Folly/Fabric (= 2020.01.13.00)
- RCTRequired (= 1000.0.0)
- RCTTypeSafety (= 1000.0.0)
- React-graphics (= 1000.0.0)
- React-jsi (= 1000.0.0)
- React-jsiexecutor (= 1000.0.0)
- ReactCommon/turbomodule/core (= 1000.0.0)
- React-Fabric/scheduler (1000.0.0):
- RCT-Folly/Fabric (= 2020.01.13.00)
- RCTRequired (= 1000.0.0)
Expand Down Expand Up @@ -850,7 +859,7 @@ SPEC CHECKSUMS:
React-Core: 2d53d893ddeff7a58e7ed51b43a15a3d94c3c4a7
React-CoreModules: c096a150e14753b07dc68a498508da4e55b026e9
React-cxxreact: 14cce64344ab482615dfe82a2cbea6eb73be6481
React-Fabric: bf713bb8a442b56361b0ed4ca7d070697cc69b38
React-Fabric: 641ddc4b27a2611f483430a043557668fec81bf9
React-graphics: 246b8e6cb4aad51271358767c965e47d692921ab
React-jsi: 08c6628096d2025d4085fbaec8fe14a3c9dc667c
React-jsiexecutor: 896c41b04121803e4ee61e4c9ed0900fdb420fea
Expand Down

0 comments on commit eb13baf

Please sign in to comment.