Files
react-native/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp
T
Rubén Norte e04d1b47b6 Move feature flags for the event loop to ReactNativeFeatureFlags (#42434)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42434

Changelog: [internal]

The flags for the event loop were set up using different mechanisms due to the limitations of the previous feature flags systems. Now we can centralize on the new system and use them consistently on Android and iOS.

Reviewed By: RSNara

Differential Revision: D52819137

fbshipit-source-id: e30a6f2e12b4a027a906502b80a70dd48bb657b6
2024-01-25 13:55:11 -08:00

92 lines
2.8 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and 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"
#include "RuntimeScheduler_Legacy.h"
#include "RuntimeScheduler_Modern.h"
#include "SchedulerPriorityUtils.h"
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/debug/SystraceSection.h>
#include <utility>
#include "ErrorUtils.h"
namespace facebook::react {
namespace {
std::unique_ptr<RuntimeSchedulerBase> getRuntimeSchedulerImplementation(
RuntimeExecutor runtimeExecutor,
std::function<RuntimeSchedulerTimePoint()> now) {
if (ReactNativeFeatureFlags::useModernRuntimeScheduler()) {
return std::make_unique<RuntimeScheduler_Modern>(
std::move(runtimeExecutor), std::move(now));
} else {
return std::make_unique<RuntimeScheduler_Legacy>(
std::move(runtimeExecutor), std::move(now));
}
}
} // namespace
RuntimeScheduler::RuntimeScheduler(
RuntimeExecutor runtimeExecutor,
std::function<RuntimeSchedulerTimePoint()> now)
: runtimeSchedulerImpl_(getRuntimeSchedulerImplementation(
std::move(runtimeExecutor),
std::move(now))) {}
void RuntimeScheduler::scheduleWork(RawCallback&& callback) noexcept {
return runtimeSchedulerImpl_->scheduleWork(std::move(callback));
}
std::shared_ptr<Task> RuntimeScheduler::scheduleTask(
SchedulerPriority priority,
jsi::Function&& callback) noexcept {
return runtimeSchedulerImpl_->scheduleTask(priority, std::move(callback));
}
std::shared_ptr<Task> RuntimeScheduler::scheduleTask(
SchedulerPriority priority,
RawCallback&& callback) noexcept {
return runtimeSchedulerImpl_->scheduleTask(priority, std::move(callback));
}
bool RuntimeScheduler::getShouldYield() const noexcept {
return runtimeSchedulerImpl_->getShouldYield();
}
bool RuntimeScheduler::getIsSynchronous() const noexcept {
return runtimeSchedulerImpl_->getIsSynchronous();
}
void RuntimeScheduler::cancelTask(Task& task) noexcept {
return runtimeSchedulerImpl_->cancelTask(task);
}
SchedulerPriority RuntimeScheduler::getCurrentPriorityLevel() const noexcept {
return runtimeSchedulerImpl_->getCurrentPriorityLevel();
}
RuntimeSchedulerTimePoint RuntimeScheduler::now() const noexcept {
return runtimeSchedulerImpl_->now();
}
void RuntimeScheduler::executeNowOnTheSameThread(RawCallback&& callback) {
return runtimeSchedulerImpl_->executeNowOnTheSameThread(std::move(callback));
}
void RuntimeScheduler::callExpiredTasks(jsi::Runtime& runtime) {
return runtimeSchedulerImpl_->callExpiredTasks(runtime);
}
void RuntimeScheduler::scheduleRenderingUpdate(
RuntimeSchedulerRenderingUpdate&& renderingUpdate) {
return runtimeSchedulerImpl_->scheduleRenderingUpdate(
std::move(renderingUpdate));
}
} // namespace facebook::react