Skip to content

Commit

Permalink
Revert D64631346: Use RuntimeScheduler in EventBeat
Browse files Browse the repository at this point in the history
Differential Revision:
D64631346

Original commit changeset: b82dca150c13

Original Phabricator Diff: D64631346

fbshipit-source-id: 89ef52e5891d9fef33494fbfcc4252cade4aa803
  • Loading branch information
Cody Pizzaia authored and facebook-github-bot committed Oct 24, 2024
1 parent 020e1b6 commit 2d97a6c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions packages/react-native/React/Fabric/AppleEventBeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace facebook::react {
AppleEventBeat::AppleEventBeat(
std::shared_ptr<OwnerBox> ownerBox,
std::unique_ptr<const RunLoopObserver> uiRunLoopObserver,
RuntimeScheduler& runtimeScheduler)
: EventBeat(std::move(ownerBox), runtimeScheduler),
RuntimeExecutor runtimeExecutor)
: EventBeat(std::move(ownerBox), std::move(runtimeExecutor)),
uiRunLoopObserver_(std::move(uiRunLoopObserver)) {
uiRunLoopObserver_->setDelegate(this);
uiRunLoopObserver_->enable();
Expand Down
4 changes: 1 addition & 3 deletions packages/react-native/React/Fabric/AppleEventBeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace facebook::react {

class RuntimeScheduler;

/*
* Event beat associated with JavaScript runtime.
* The beat is called on `RuntimeExecutor`'s thread induced by the UI thread
Expand All @@ -25,7 +23,7 @@ class AppleEventBeat : public EventBeat, public RunLoopObserver::Delegate {
AppleEventBeat(
std::shared_ptr<OwnerBox> ownerBox,
std::unique_ptr<const RunLoopObserver> uiRunLoopObserver,
RuntimeScheduler& RuntimeScheduler);
RuntimeExecutor runtimeExecutor);

#pragma mark - RunLoopObserver::Delegate

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ - (RCTScheduler *)_createScheduler
toolbox.bridgelessBindingsExecutor = _bridgelessBindingsExecutor;

toolbox.eventBeatFactory =
[runtimeScheduler](std::shared_ptr<EventBeat::OwnerBox> ownerBox) -> std::unique_ptr<EventBeat> {
[runtimeExecutor](std::shared_ptr<EventBeat::OwnerBox> ownerBox) -> std::unique_ptr<EventBeat> {
auto runLoopObserver =
std::make_unique<const MainRunLoopObserver>(RunLoopObserver::Activity::BeforeWaiting, ownerBox->owner);
return std::make_unique<AppleEventBeat>(std::move(ownerBox), std::move(runLoopObserver), *runtimeScheduler);
return std::make_unique<AppleEventBeat>(std::move(ownerBox), std::move(runLoopObserver), runtimeExecutor);
};

RCTScheduler *scheduler = [[RCTScheduler alloc] initWithToolbox:toolbox];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace facebook::react {
AndroidEventBeat::AndroidEventBeat(
std::shared_ptr<OwnerBox> ownerBox,
EventBeatManager* eventBeatManager,
RuntimeScheduler& runtimeScheduler,
RuntimeExecutor runtimeExecutor,
jni::global_ref<jobject> javaUIManager)
: EventBeat(std::move(ownerBox), runtimeScheduler),
: EventBeat(std::move(ownerBox), std::move(runtimeExecutor)),
eventBeatManager_(eventBeatManager),
javaUIManager_(std::move(javaUIManager)) {
eventBeatManager->addObserver(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AndroidEventBeat final : public EventBeat,
AndroidEventBeat(
std::shared_ptr<OwnerBox> ownerBox,
EventBeatManager* eventBeatManager,
RuntimeScheduler& runtimeScheduler,
RuntimeExecutor runtimeExecutor,
jni::global_ref<jobject> javaUIManager);

~AndroidEventBeat() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,25 +471,28 @@ void FabricUIManagerBinding::installFabricUIManager(

auto runtimeExecutor = runtimeExecutorHolder->cthis()->get();

auto runtimeScheduler = runtimeSchedulerHolder->cthis()->get().lock();
if (runtimeScheduler) {
runtimeExecutor =
[runtimeScheduler](
std::function<void(jsi::Runtime & runtime)>&& callback) {
runtimeScheduler->scheduleWork(std::move(callback));
};
contextContainer->insert(
"RuntimeScheduler", std::weak_ptr<RuntimeScheduler>(runtimeScheduler));
if (runtimeSchedulerHolder) {
auto runtimeScheduler = runtimeSchedulerHolder->cthis()->get().lock();
if (runtimeScheduler) {
runtimeExecutor =
[runtimeScheduler](
std::function<void(jsi::Runtime & runtime)>&& callback) {
runtimeScheduler->scheduleWork(std::move(callback));
};
contextContainer->insert(
"RuntimeScheduler",
std::weak_ptr<RuntimeScheduler>(runtimeScheduler));
}
}

EventBeat::Factory eventBeatFactory =
[eventBeatManager, &runtimeScheduler, globalJavaUiManager](
[eventBeatManager, runtimeExecutor, globalJavaUiManager](
std::shared_ptr<EventBeat::OwnerBox> ownerBox)
-> std::unique_ptr<EventBeat> {
return std::make_unique<AndroidEventBeat>(
std::move(ownerBox),
eventBeatManager,
*runtimeScheduler,
runtimeExecutor,
globalJavaUiManager);
};

Expand Down
29 changes: 14 additions & 15 deletions packages/react-native/ReactCommon/react/renderer/core/EventBeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

#include "EventBeat.h"

#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
#include <utility>

namespace facebook::react {

EventBeat::EventBeat(
std::shared_ptr<OwnerBox> ownerBox,
RuntimeScheduler& runtimeScheduler)
: ownerBox_(std::move(ownerBox)), runtimeScheduler_(runtimeScheduler) {}
RuntimeExecutor runtimeExecutor)
: ownerBox_(std::move(ownerBox)),
runtimeExecutor_(std::move(runtimeExecutor)) {}

void EventBeat::request() const {
isRequested_ = true;
Expand All @@ -33,18 +33,17 @@ void EventBeat::induce() const {
isRequested_ = false;
isBeatCallbackScheduled_ = true;

runtimeScheduler_.scheduleWork(
[this, ownerBox = ownerBox_](jsi::Runtime& runtime) {
auto owner = ownerBox->owner.lock();
if (!owner) {
return;
}

isBeatCallbackScheduled_ = false;
if (beatCallback_) {
beatCallback_(runtime);
}
});
runtimeExecutor_([this, ownerBox = ownerBox_](jsi::Runtime& runtime) {
auto owner = ownerBox->owner.lock();
if (!owner) {
return;
}

isBeatCallbackScheduled_ = false;
if (beatCallback_) {
beatCallback_(runtime);
}
});
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@

#pragma once

#include <ReactCommon/RuntimeExecutor.h>
#include <atomic>
#include <functional>
#include <memory>

namespace facebook::react {
class RuntimeScheduler;
}

namespace facebook::jsi {
class Runtime;
}
Expand Down Expand Up @@ -59,7 +56,7 @@ class EventBeat {

explicit EventBeat(
std::shared_ptr<OwnerBox> ownerBox,
RuntimeScheduler& runtimeScheduler);
RuntimeExecutor runtimeExecutor);

virtual ~EventBeat() = default;

Expand Down Expand Up @@ -91,7 +88,7 @@ class EventBeat {
mutable std::atomic<bool> isRequested_{false};

private:
RuntimeScheduler& runtimeScheduler_;
RuntimeExecutor runtimeExecutor_;
mutable std::atomic<bool> isBeatCallbackScheduled_{false};
};

Expand Down

0 comments on commit 2d97a6c

Please sign in to comment.