diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index a91a63190..e77d6e1d0 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -30,7 +30,7 @@ #import #import "MainRunLoopEventBeat.h" -#import "MessageQueueEventBeat.h" +#import "RuntimeEventBeat.h" #import "RCTConversions.h" using namespace facebook::react; @@ -165,12 +165,12 @@ using namespace facebook::react; }); }; - EventBeatFactory synchronousBeatFactory = [messageQueueThread]() { - return std::make_unique(messageQueueThread); + EventBeatFactory synchronousBeatFactory = [runtimeExecutor]() { + return std::make_unique(runtimeExecutor); }; - EventBeatFactory asynchronousBeatFactory = [messageQueueThread]() { - return std::make_unique(messageQueueThread); + EventBeatFactory asynchronousBeatFactory = [runtimeExecutor]() { + return std::make_unique(runtimeExecutor); }; contextContainer->registerInstance(synchronousBeatFactory, "synchronous"); diff --git a/React/Fabric/Utils/MainRunLoopEventBeat.h b/React/Fabric/Utils/MainRunLoopEventBeat.h index abfd8c230..b0e029eb6 100644 --- a/React/Fabric/Utils/MainRunLoopEventBeat.h +++ b/React/Fabric/Utils/MainRunLoopEventBeat.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include namespace facebook { @@ -21,15 +21,15 @@ class MainRunLoopEventBeat final: public EventBeat { public: - MainRunLoopEventBeat(std::shared_ptr messageQueueThread); + MainRunLoopEventBeat(RuntimeExecutor runtimeExecutor); ~MainRunLoopEventBeat(); void induce() const override; private: - void blockMessageQueueAndThenBeat() const; + void lockExecutorAndBeat() const; - std::shared_ptr messageQueueThread_; + const RuntimeExecutor runtimeExecutor_; CFRunLoopObserverRef mainRunLoopObserver_; }; diff --git a/React/Fabric/Utils/MainRunLoopEventBeat.mm b/React/Fabric/Utils/MainRunLoopEventBeat.mm index 33e8e9a38..5762c6990 100644 --- a/React/Fabric/Utils/MainRunLoopEventBeat.mm +++ b/React/Fabric/Utils/MainRunLoopEventBeat.mm @@ -11,8 +11,8 @@ namespace facebook { namespace react { -MainRunLoopEventBeat::MainRunLoopEventBeat(std::shared_ptr messageQueueThread): - messageQueueThread_(std::move(messageQueueThread)) { +MainRunLoopEventBeat::MainRunLoopEventBeat(RuntimeExecutor runtimeExecutor): + runtimeExecutor_(std::move(runtimeExecutor)) { mainRunLoopObserver_ = CFRunLoopObserverCreateWithHandler( @@ -25,7 +25,7 @@ MainRunLoopEventBeat::MainRunLoopEventBeat(std::shared_ptr m return; } - this->blockMessageQueueAndThenBeat(); + this->lockExecutorAndBeat(); } ); @@ -45,11 +45,11 @@ void MainRunLoopEventBeat::induce() const { } RCTExecuteOnMainQueue(^{ - this->blockMessageQueueAndThenBeat(); + this->lockExecutorAndBeat(); }); } -void MainRunLoopEventBeat::blockMessageQueueAndThenBeat() const { +void MainRunLoopEventBeat::lockExecutorAndBeat() const { // Note: We need the third mutex to get back to the main thread before // the lambda is finished (because all mutexes are allocated on the stack). @@ -61,7 +61,7 @@ void MainRunLoopEventBeat::blockMessageQueueAndThenBeat() const { mutex2.lock(); mutex3.lock(); - messageQueueThread_->runOnQueue([&]() { + runtimeExecutor_([&](jsi::Runtime &runtime) { mutex1.unlock(); mutex2.lock(); mutex3.unlock(); diff --git a/React/Fabric/Utils/MessageQueueEventBeat.h b/React/Fabric/Utils/RuntimeEventBeat.h similarity index 63% rename from React/Fabric/Utils/MessageQueueEventBeat.h rename to React/Fabric/Utils/RuntimeEventBeat.h index 093798bad..1ddd3983c 100644 --- a/React/Fabric/Utils/MessageQueueEventBeat.h +++ b/React/Fabric/Utils/RuntimeEventBeat.h @@ -7,26 +7,28 @@ #include #include -#include +#include #include namespace facebook { namespace react { /* - * Event beat that associated with MessageQueueThread. + * Event beat associated with JavaScript runtime. + * The beat is called on `RuntimeExecutor`'s thread induced by the main thread + * event loop. */ -class MessageQueueEventBeat: +class RuntimeEventBeat: public EventBeat { public: - MessageQueueEventBeat(const std::shared_ptr &messageQueueThread); - ~MessageQueueEventBeat(); + RuntimeEventBeat(RuntimeExecutor runtimeExecutor); + ~RuntimeEventBeat(); void induce() const override; private: - const std::shared_ptr messageQueueThread_; + const RuntimeExecutor runtimeExecutor_; CFRunLoopObserverRef mainRunLoopObserver_; mutable std::atomic isBusy_ {false}; }; diff --git a/React/Fabric/Utils/MessageQueueEventBeat.mm b/React/Fabric/Utils/RuntimeEventBeat.mm similarity index 84% rename from React/Fabric/Utils/MessageQueueEventBeat.mm rename to React/Fabric/Utils/RuntimeEventBeat.mm index c6b87dd34..911ab6061 100644 --- a/React/Fabric/Utils/MessageQueueEventBeat.mm +++ b/React/Fabric/Utils/RuntimeEventBeat.mm @@ -5,13 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -#include "MessageQueueEventBeat.h" +#include "RuntimeEventBeat.h" namespace facebook { namespace react { -MessageQueueEventBeat::MessageQueueEventBeat(const std::shared_ptr &messageQueueThread): - messageQueueThread_(messageQueueThread) { +RuntimeEventBeat::RuntimeEventBeat(RuntimeExecutor runtimeExecutor): + runtimeExecutor_(std::move(runtimeExecutor)) { mainRunLoopObserver_ = CFRunLoopObserverCreateWithHandler( @@ -31,12 +31,12 @@ MessageQueueEventBeat::MessageQueueEventBeat(const std::shared_ptrrunOnQueue([=]() mutable { + runtimeExecutor_([=](jsi::Runtime &runtime) mutable { this->beat(); isBusy_ = false; #ifndef NDEBUG