-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5f0bf8b
commit eb13baf
Showing
9 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
45 changes: 45 additions & 0 deletions
45
ReactCommon/react/renderer/runtimescheduler/RuntimeSchedulerBinding.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
35 changes: 35 additions & 0 deletions
35
ReactCommon/react/renderer/runtimescheduler/RuntimeSchedulerBinding.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters